Answers for "how to find specific field in all documents under a collection in mongodb in node js"

Go
0

FIND SPECIFIC FIELDS FROM SunDOCUMENTS OF ALL DOCUMENTS UNDER A COLLECTION IN MONGODB

db.inventory.find( { item: /^j/ }, { 'size.h': 1 } )
Posted by: Guest on November-24-2021
0

FIND SPECIFIC FIELDS FROM SunDOCUMENTS OF ALL DOCUMENTS UNDER A COLLECTION IN MONGODB

//use when you want `_id,size` (As object) with its only property `h` in 
//$project,

db.inventory.aggregate([{$match:{  item: /^j/  } },{ $project:{ 
"size.h":"$size.h" } }])

//use when you want `_id,size` size ase whole object  
//$project,

db.inventory.aggregate([{$match:{  item: /^j/  } },{ $project:{ "size":1 } 
}])
Posted by: Guest on November-24-2021

Code answers related to "how to find specific field in all documents under a collection in mongodb in node js"

Browse Popular Code Answers by Language