I am using mongoose with nodeJS. Consider the following schema:
var PersonSchema = new mongoose.Schema({
"name": {type: String, default: "Human"},
"age": {type: Number, defualt:20}
});
mongoose.model('Person', PersonSchema);
var order = new Order({
name:null
});
This creates a new Person document with name set to null.
{
name:null,
age: 20
}
Is there anyway to check if the property being created/updated is null and if it is null set it back to default. The following declaration
var order = new Order();
order.name = null;
order.save(cb);
should create a new Person document with name set to default.
{
name:"Human",
age: 20
}
How would one implement this using NodeJs and mongoose.