question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Schema.type.Mixed and deep modification does not update document

See original GitHub issue

When I try to update a deep nested field, the query is well sent to MongoDB but when I do a find on this doc, the field is not updated.

Example

var DtSchema = mongoose.Schema({
     nested : Schema.type.mixed
});

var Dt = mongoose.model('Dt', DtSchema)

var test = new Dt({nested : { a : 'test', b : { c : { d : null } } } });

test.save(function(err, _test) {
    _test.nested.b.c.d = 'Hello !';
    _test.save(function(err, _test) {
       // _test is okay, the field nested.b.c.d is updated 

       Dt.findOne({_id : _test._id}, function(err, doc) {
           // Here The doc has not the nested.b.c.d field updated
       });
    })
});

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:16

github_iconTop GitHub Comments

4reactions
mattcaseycommented, Nov 5, 2014

Did you guys try using markModified()? Mixed types won’t save updates unless you tell Mongoose something has changed

1reaction
bhagabancommented, Dec 5, 2017

If you do this, it will work.

var nested = JSON.parse(JSON.stringify(_test.nested)); //now changed the nested object. nested.a = “new value” _test.nested = nested; _test.save();

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I update a [Schema.Types.Mixed]? - Stack Overflow
I want to add another field "youtube". How do I write updateOne query such that it upserts this new field in profiles? And...
Read more >
Manage Schemas for Topics in Control Center
To learn more, see Schema References in the schema formats developer documentation. View, edit, or delete schema references for a topic. Existing schema...
Read more >
Mongoose v6.8.1: Schema
Using this exposed access to the Mixed SchemaType, we can use them in our schema. const Mixed = mongoose.Schema.Types.Mixed; new mongoose.
Read more >
Specifying a schema | BigQuery - Google Cloud
After loading data or creating an empty table, you can modify the table's ... in your schema file by using the Google Cloud...
Read more >
MongoDB | NestJS - A progressive Node.js framework
Hint Note you can also generate a raw schema definition using the DefinitionsFactory class (from the nestjs/mongoose ). This allows you to manually...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found