DEV Community

loading...

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

Peter Lau
Curious about everything about programming. Open mind to everything unfamiliar with. Raise qarabbit (https://quickanswer.awesomefe.dev/about/) online.
Originally published at quickanswer.awesomefe.dev ・1 min read
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:

Discussion (0)

Forem Open with the Forem app