You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
varmongoose=require('mongoose');vardictionaryPlugin=require('mongoose-dictionary')(mongoose);mongoose.connect('mongodb://localhost/dictionary_testing');varMySchema=newmongoose.Schema({title: String,});MySchema.plugin(dictionaryPlugin,{fields: {nameOfTheDictionaryField: {aFieldOfDictionary: String}}});varMyModel=mongoose.model('MyModel',MySchema);vardoc=newMyModel({title: 'a'});// IMPORTANT THIS MUST BE CALLED WHEN CREATING A NEW DOCUMENT LOCALLY (NOT RETURNED FROM DB)doc.emit('new',doc);doc.dictionary.$add('key',{aFieldOfDictionary: 123// Using a number to show that casting is working});doc.dictionary.$add('anotherKey',{aFieldOfDictionary: 123// Using a number to show that casting is working});doc.dictionary.$remove('anotherKey');doc.save(function(err,doc){console.log(err,doc)});