Answers for "find all documents with a specific field mongodb"

Go
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 "find all documents with a specific field mongodb"

Browse Popular Code Answers by Language