The MongoDB Query API is the primary interface for working with MongoDB data. It supports CRUD operations for creating, reading, updating, and deleting documents, and aggregation pipelines for multistage transformation and analysis. Read queries can use filters, projections, and sorting to return the data an application needs. section 1.5
Find, update, and remove books
In MongoDB Shell, these operations find a book by title, change its publisher, and delete books marked out of print: ```javascript db.books.find({ title: "MongoDB 8.0 in Action" }) db.books.updateOne( { title: "MongoDB 8.0 in Action" }, { $set: { publisher: "Manning Publications Co" } } ) db.books.deleteMany({ status: "out of print" }) ``` Check the filter before running an update or deletion: it determines which documents match. section 1.1
Choose the query form to match the job:
- Use CRUD operations for direct document management. Run queries through mongosh, MongoDB Compass, or a MongoDB driver. section 1.5
- Use aggregation pipelines to reshape and analyze data. Operators such as $lookup and $unionWith combine data from collections; other stages support search, vector search, and geospatial or graph queries. section 1.5
- In Atlas, the same document model and Query API also support stream processing. An Atlas Stream Processor continuously runs an aggregation pipeline over incoming events and sends results to a destination. section 15.3
