I have a schema of Dog with strict set to false, allowing for values not in the schema to be saved. However, I can't seem to use dot notation to set values like so:
var dog = new Dog();
dog.name = "Barry"; // works because name is in schema
dog.notInSchema = "This should work!" // doesn't work because its not in the schema
dog.save(...)
Something like this does work:
var dog = new Dog({name : "kyle", notInSChema : "This works and saves" })
dog.save(...)
I need to use dot notation here with fields that aren't in the schema, how can I do this?
The best way to set items on a Mongoose model is with Model#set. In your example, this would be:
var dog = new Dog();
Dog.set('name', 'Barry');
Dog.set('notInSchema', 'this does work');
dog.save(callback);
See http://mongoosejs.com/docs/api.html#document_Document-set