DEV Community

Peter Lau
Peter Lau

Posted on • Originally published at quickanswer.awesomefe.dev

1

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)

ACI image

ACI.dev: Fully Open-source AI Agent Tool-Use Infra (Composio Alternative)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Check out our GitHub!