I quite a problem while I'm attempting to update an embedded document in mongodb. I've tried two methods and neither work, and I've searched everywhere for reasons why this it's not updating. Anyway, my schema looks like this (I may note that the embedded document I'm trying to update is a Mixed type).
var UserModel = new mongoose.Schema({
account: String,
salt: String,
password: String,
highlight_words: String,
networks: {},
ip: String,
ident: String,
is_connected: Boolean,
account_type: String
});
I've tried updating 'networks' with these two snippets of code and neither work. I'm about to pull my hair out.
self.userModel.update({account: key}, {networks: self.client_data[key]['networks']}, function(err) {});
And (note that I've tried adding a callback to save(), and it executes without error)
self.userModel.findOne({account: key}, function(err, doc) {
doc.networks = self.client_data[key]['networks'];
doc.markModified('networks').save();
});
Any help would be appreciated! Thanks!
Edit:
The problem was that the object was like so {'some.thing': {more: 'stuff'}}
obviously it didn't like the . which is understandable!
Try doc.markModified('networks');
. It looks like networks
is a schemaless type. Mongoose can't autodetect changes to schemaless types.
You need to define your schema fully for this to work. For example:
networks { type : "String" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With