Is there any way that will only return the field of the store that has grade B?

I tried: db.restaurant.find( {"Result.Grade" : "B"} ) But it will return back all document content with grade B.

Thanks!!

1 Answers

0
Anthony Winzlet On Best Solutions

First argument in the find query is for filter. Use second argument and pass the fields you want to retrieve.

db.restaurant.find(
  { "Result.Grade" : "B" },   //filter
  { "Name": 1, "Number": 1 }      //projection
)

With the mongodb node driver use .project() cursor method

db.restaurant.find(
  { "Result.Grade" : "B" },
).project({ "Name": 1, "Number": 1 })