I am trying to start using Mongoose as an ODM for MongoDB with my node.js application. I have noticed that when I design a schema with an embedded document that if I don't add a value to it, it store a blank array "[]" in Mongo. Why is this? I am trying to store historical changes to records and a blank array would mean that that change deleted the value. Here is a sample schema.
schema.Client = new mongoose.Schema({
name:{type:String, required:true},
products:[{
name:{type:String, index:true},
startDate:Date,
endDate:Date
}],
subdomain:{type:String, index:{unique:true}},
})
Here is the resulting document when I save a document with just name and subdomain.
{
"name": "Smith Company",
"products": [],
"subdomain": "smith"
}
Why did it add products with a blank array by default and how can I stop it?
See Question&Answers more detail:os