Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mongodb-preview.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

This guide organizes the core platform capabilities into practical sections you can use when building application features.

CRUD Operations

Create, read, update, and delete operations are the foundation of most operational workloads. Keep write paths idempotent where possible and scope reads to indexed fields.
db.accounts.updateOne(
  { _id: accountId },
  { $set: { tier: "pro" }, $currentDate: { updatedAt: true } }
)

Indexes

Indexes reduce scan volume and improve latency. Start by indexing:
  • High-selectivity filter fields
  • Sort keys used in frequent queries
  • Compound patterns where filter + sort are stable
Use explain plans regularly to validate index effectiveness.

Data Modeling

Choose between embedding and referencing based on read/write patterns:
  • Embed when data is read together and bounded in size.
  • Reference when relationships are many-to-many or independently updated.
Model for your most common query patterns first.

Aggregation Operations

Aggregation pipelines let you transform and compute server-side:
db.events.aggregate([
  { $match: { type: "purchase" } },
  { $group: { _id: "$country", revenue: { $sum: "$amount" } } },
  { $sort: { revenue: -1 } }
])

Geospatial Queries

Use 2dsphere indexes for location workloads such as proximity and region containment queries.
db.places.createIndex({ loc: "2dsphere" })

Time Series Collections

Time series collections optimize storage and query patterns for timestamped measurements. Use appropriate timeField and metaField choices to improve bucketing and scan efficiency.

Change Streams

Change streams provide an event feed of inserts, updates, deletes, and metadata changes. They are useful for reactive architectures, projections, and background workflows.

Transactions

Transactions provide atomicity across multiple documents and collections. Use them when business invariants span more than one write target.

Replication

Replica sets provide high availability and failover. Design applications to retry transient write and read errors during elections.

Sharding

Sharding distributes data horizontally across shards. Choose shard keys based on cardinality, write distribution, and query routing requirements.

MQL Reference

Operations and Security

Search and AI

Databases and Collections