Answers for "mongodb get a single field of all documents"

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 "mongodb get a single field of all documents"

Browse Popular Code Answers by Language