liveBook · Manning

MongoDB Query API

As explained in MongoDB 8.0 in Action, Third Edition

The MongoDB Query API is the interface for querying, modifying, and transforming data in MongoDB through CRUD operations and aggregation pipelines.

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

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Introduces CRUD commands and surveys aggregation capabilities, deferring detailed syntax and pipelines.
Examples
Shows book-collection commands that find by title, update a publisher, and delete documents by publication status.
What it assumes
Introduces queries against JSON-like documents and defines CRUD without requiring prior MongoDB query syntax.
What you can do after
Apply it via mongosh, Compass, or MongoDB drivers to run document queries and choose CRUD or aggregation for a task.
How it connects
Connects the document model and CRUD to aggregation pipelines, indexes, Atlas Search, and Atlas Stream Processing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.