mongoose nested object code example
Example 1: mongoose iupdate nested
blog.findByIdAndUpdate(entityId, {$set: {'meta.favs': 56}}, function(err, doc) {
console.log(doc);
});
Example 2: mongoose select nested
var fields = { 'properties.OBJECTID': 1, 'properties.TIMESTAMP': 1 };
var query = Feature.find({id: 1}).select(fields);
Example 3: mongoose nested require
var jobSchema = Schema({
negotiation: { state: { type: String, required: hasNegotiation } }
});
function hasNegotiation() {
return this.negotiation && Object.keys(this.negotiation).length > 0;
}
Example 4: mongoose nested object without id
var subSchema = mongoose.Schema({
},{ _id : false });
Example 5: mongoose find by nested property
System.findOne({ 'nodes.main.Alpha': 23000}, function(err, system){
if(err){console.log(err);}
else{console.log(system);}
});