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.

MongoDB Query Language (MQL) is the API surface you use to filter, project, update, and aggregate data in collections. This page summarizes the concepts most teams use daily and points to related local guides in this docs set.

MQL Reference

MQL expressions are BSON-shaped documents. You can use direct field equality, operator documents, or a mix of both:
{
  status: "active",
  score: { $gte: 90 },
  tags: { $in: ["premium", "beta"] }
}

Predicate Patterns

Use these operator families to model common query behavior:
  • Comparison: $eq, $ne, $gt, $gte, $lt, $lte
  • Element: $exists, $type
  • Logical: $and, $or, $nor, $not
  • Array: $all, $elemMatch, $size
  • Evaluation: $regex, $expr

Projection Patterns

Return only the fields your application needs:
db.users.find(
  { status: "active" },
  { _id: 0, email: 1, lastLoginAt: 1 }
)
For nested structures, dot notation and projection operators keep payloads small and predictable.

Update Expression Basics

Use operator-based updates to mutate documents safely:
db.users.updateOne(
  { _id: userId },
  {
    $set: { status: "active", profile.updatedAt: new Date() },
    $inc: { loginCount: 1 }
  }
)

Aggregation as Extended MQL

Aggregation pipelines are ordered arrays of stages:
db.orders.aggregate([
  { $match: { status: "paid" } },
  { $group: { _id: "$customerId", total: { $sum: "$amount" } } },
  { $sort: { total: -1 } }
])
If you need aggregation-specific guidance, see /docs/reference/manual-core-capabilities#aggregation-operations.

Core Capabilities

Operations and Security

Documents

Databases and Collections