Thursday, 27 April 2017

mongoose save not updating Schema.Types.Mixed field

mongoose save not updating Schema.Types.Mixed data

I am new to node.js and mongoose. I have a complex data model with contains a Schema.Types.Mixed property:

var myDataSchema = Schema({
  name: String,
  description: String,
  jdata: Schema.Types.Mixed,
  ...
})

I have recently discovered that when I update the data in instance and try to call save:

myDataInstance.jdata = newData;
myDataInstance.description = "something new";
...

myDataInstance.save( function( err, myDataInstance, numAffected ){
  // numAffected is 1, other fields are updated but jdata was not updated
});

the jdata field is not updated in mongo, but other fields are. What am I missing? In my case jdata contains an 2 arrays like the following:

{
  rows: [ { label_1: val_1 }, { label_2: val_2 } ],
  columns: [ "label_1", "label_2"]
}



via J21042

No comments:

Post a Comment