mongoose find nested schema code example

Example 1: mongoose find get nested prop only

ListModel.findOne({
	"_id" : "57e6bcab6b383120f0395aed", 'recipients.status' : 1
  },
  {
  	_id:1, name: 1, subject:1,'recipients.$': 1
   },
   function(err,list) {...}
);

Example 2: mongoose select nested

var fields = { 'properties.OBJECTID': 1, 'properties.TIMESTAMP': 1 };
var query = Feature.find({id: 1}).select(fields);

Example 3: mongoose find by nested property

System.findOne({ 'nodes.main.Alpha': 23000}, function(err, system){
   if(err){console.log(err);}
   else{console.log(system);}
 });

Tags:

Misc Example