1
{People:"1","Location":"US","Name":[{"first":"Tom","last":"Brady"},
{"first":"Jack","last":"Sparrow"},{"first":"Haha","last":"OhOh"}]}

I have some data in MongoDB, the data structure is like this, how Can I search "Tom" and only return

 {People:"1","Location":"US","Name":[{"first":"Tom","last":"Brady"}]}
Jason Z
  • 265
  • 1
  • 6
  • 12

1 Answers1

1

try

db.collectionName.find({"Name.first": "Tom"}, {_id: 0, People: 1, Location: 1, "Name.$": 1});

djaszczurowski
  • 4,385
  • 1
  • 18
  • 28