DEV Community

Peter Lau
Peter Lau

Posted on • Originally published at quickanswer.awesomefe.dev

MongoDB |> How to Select a Single Field for All Documents in a MongoDB Collection

db.inventory.find( { type: 'food' }, { item: 1, qty: 1 } )

In above example from the folks at Mongo, the returned documents will contain only the fields of item, qty, and _id.

db.inventory.find( { type: 'food' }, { item: 1, qty: 0 } )

In above example from the folks at Mongo, the returned documents will contain only the fields of item, and _id.


References:

Top comments (0)