Back to blog
|David Durika

7 MongoDB Queries You Can Generate in Seconds with Mingo's AI

Practical examples of using Mingo's AI assistant to generate MongoDB queries from plain English, including filters, array queries, and multi-stage aggregation pipelines.

7 MongoDB Queries You Can Generate in Seconds with Mingo's AI

Skip the syntax, keep the intent

Writing MongoDB queries isn't hard. Writing them fast is. Especially when you're debugging at 4pm and the pipeline you need has five stages, two $lookups, and a $group with computed fields.

Mingo's AI assistant lets you describe what you want and get a working query back. Here are seven real examples, ordered from simple to complex, showing what that looks like in practice.

1. Basic Date Range Filter

You type:

Show me all orders from the last 30 days

The AI generates:

{
  "createdAt": {
    "$gte": { "$date": "2026-02-07T00:00:00.000Z" }
  }
}

No more calculating dates manually or looking up ISODate syntax. The AI knows today's date and does the math.

2. Compound Filter with Nested Fields

You type:

Find users with an enterprise subscription who signed up before 2025

The AI generates:

{
  "subscription.tier": "enterprise",
  "createdAt": { "$lt": { "$date": "2025-01-01T00:00:00.000Z" } }
}

Here's where the tool loop matters. The AI doesn't guess that the field is called subscription.tier. It requests field samples from your collection, discovers the actual field path and value format, and builds the query accordingly.

3. Regex Search Across Multiple Fields

You type:

Find documents where either the name or email contains "acme"

The AI generates:

{
  "$or": [
    { "name": { "$regex": "acme", "$options": "i" } },
    { "email": { "$regex": "acme", "$options": "i" } }
  ]
}

Case-insensitive by default, because that's almost always what you want.

4. Array Queries

You type:

Find products tagged with both "electronics" and "sale"

The AI generates:

{
  "tags": { "$all": ["electronics", "sale"] }
}

$all vs $in vs $elemMatch. The AI picks the right operator based on what you described.

5. Aggregation: Group and Count

You type:

How many orders per status? Sort by count descending.

The AI generates:

[
  { "$group": { "_id": "$status", "count": { "$sum": 1 } } },
  { "$sort": { "count": -1 } }
]

Two stages, clean output. The AI knows you want a pipeline, not a find query, because you're in the Aggregation view.

6. Aggregation: Lookup with Filtering

You type:

Join orders with customers collection, only include orders above $1000, show customer name and order total

The AI generates:

[
  { "$match": { "total": { "$gt": 1000 } } },
  {
    "$lookup": {
      "from": "customers",
      "localField": "customerId",
      "foreignField": "_id",
      "as": "customer"
    }
  },
  { "$unwind": "$customer" },
  {
    "$project": {
      "customerName": "$customer.name",
      "total": 1,
      "_id": 0
    }
  }
]

Four stages that would take a few minutes to write by hand. The AI places $match before $lookup for performance (filter first, then join). It also discovers the correct field names (customerId, not customer_id) by examining your schema.

7. Aggregation: Time-Series Analysis

You type:

Show monthly revenue for the past year, grouped by month

The AI generates:

[
  {
    "$match": {
      "createdAt": { "$gte": { "$date": "2025-03-01T00:00:00.000Z" } }
    }
  },
  {
    "$group": {
      "_id": {
        "year": { "$year": "$createdAt" },
        "month": { "$month": "$createdAt" }
      },
      "revenue": { "$sum": "$total" }
    }
  },
  {
    "$sort": { "_id.year": 1, "_id.month": 1 }
  },
  {
    "$project": {
      "_id": 0,
      "month": {
        "$concat": [
          { "$toString": "$_id.year" },
          "-",
          {
            "$cond": [
              { "$lt": ["$_id.month", 10] },
              { "$concat": ["0", { "$toString": "$_id.month" }] },
              { "$toString": "$_id.month" }
            ]
          }
        ]
      },
      "revenue": 1
    }
  }
]

Date extraction, grouping, sorting, and string formatting in one pipeline. The kind of query where you'd normally have three browser tabs open with MongoDB docs.

The point

Same flow every time: describe what you want, the AI checks your schema (and field values if needed), you get a query you can apply with one click.

The queries get better because the AI doesn't just guess from structure. It can request field samples and distinct values to nail the details. That's why the subscription.tier example above works on the first try instead of generating subscription.plan and hoping.

Open any collection in Mingo, press Cmd+Shift+A (or Ctrl+Shift+A), and try it. Works with OpenAI, Claude, Gemini, or Grok. Your own API key, your machine.