Use MongoDB Query Tester

Enter your data below to use the MongoDB Query Tester

📌 Try these examples:
RESULT

Last updated

Testing a Basic Filter Query

Paste sample documents into the collection panel, then run a filter query:

// Sample documents (paste into collection panel)
[
  { "_id": 1, "name": "Alice", "age": 28, "role": "admin" },
  { "_id": 2, "name": "Bob", "age": 35, "role": "user" },
  { "_id": 3, "name": "Carol", "age": 22, "role": "user" },
  { "_id": 4, "name": "Dave", "age": 41, "role": "moderator" }
]

// Query
{ "role": "user" }

// Result (2 documents matched)
[
  { "_id": 2, "name": "Bob", "age": 35, "role": "user" },
  { "_id": 3, "name": "Carol", "age": 22, "role": "user" }
]

Results appear instantly with syntax highlighting. The result count confirms 2 of 4 documents matched.

Testing Comparison Operators

Find users older than 30:

// Query
{ "age": { "$gt": 30 } }

// Result
[
  { "_id": 2, "name": "Bob", "age": 35, "role": "user" },
  { "_id": 4, "name": "Dave", "age": 41, "role": "moderator" }
]

Test the boundary: change $gt to $gte and set the value to 35 — only Bob matches. This kind of quick iteration is much faster than running queries against a real database.

Testing an Aggregation Pipeline Stage by Stage

Build a pipeline to calculate average age by role:

// Sample data
[
  { "name": "Alice", "age": 28, "role": "admin" },
  { "name": "Bob", "age": 35, "role": "user" },
  { "name": "Carol", "age": 22, "role": "user" },
  { "name": "Dave", "age": 41, "role": "moderator" },
  { "name": "Eve", "age": 31, "role": "user" }
]

// Stage 1: $group
{ "$group": { "_id": "$role", "avg_age": { "$avg": "$age" }, "count": { "$sum": 1 } } }

// After Stage 1:
[
  { "_id": "user", "avg_age": 29.33, "count": 3 },
  { "_id": "admin", "avg_age": 28, "count": 1 },
  { "_id": "moderator", "avg_age": 41, "count": 1 }
]

// Stage 2: $sort
{ "$sort": { "avg_age": -1 } }

// Final result:
[
  { "_id": "moderator", "avg_age": 41, "count": 1 },
  { "_id": "user", "avg_age": 29.33, "count": 3 },
  { "_id": "admin", "avg_age": 28, "count": 1 }
]

The tester shows intermediate results after each stage. If the final output is wrong, you can see exactly which stage produced unexpected results.

Debugging a $lookup Stage

Test a join between orders and users collections:

// orders collection
[
  { "_id": 1, "user_id": 10, "amount": 99.99 },
  { "_id": 2, "user_id": 11, "amount": 149.50 },
  { "_id": 3, "user_id": 10, "amount": 25.00 }
]

// users collection (add as second collection in tester)
[
  { "_id": 10, "name": "Alice", "email": "alice@example.com" },
  { "_id": 11, "name": "Bob", "email": "bob@example.com" }
]

// Pipeline
[
  {
    "$lookup": {
      "from": "users",
      "localField": "user_id",
      "foreignField": "_id",
      "as": "user_info"
    }
  }
]

// Result — user_info is an array with the matched user document
[
  { "_id": 1, "user_id": 10, "amount": 99.99, "user_info": [{ "_id": 10, "name": "Alice" }] },
  { "_id": 2, "user_id": 11, "amount": 149.50, "user_info": [{ "_id": 11, "name": "Bob" }] },
  { "_id": 3, "user_id": 10, "amount": 25.00, "user_info": [{ "_id": 10, "name": "Alice" }] }
]

Testing Update Operations

Verify that an update modifies the correct documents:

// Before update
[
  { "_id": 1, "status": "pending", "amount": 50 },
  { "_id": 2, "status": "pending", "amount": 200 },
  { "_id": 3, "status": "shipped", "amount": 75 }
]

// Update query
filter: { "status": "pending", "amount": { "$gt": 100 } }
update: { "$set": { "status": "flagged", "flagged_at": "2024-03-17" } }

// After update — only document 2 matched the filter
[
  { "_id": 1, "status": "pending", "amount": 50 },
  { "_id": 2, "status": "flagged", "amount": 200, "flagged_at": "2024-03-17" },
  { "_id": 3, "status": "shipped", "amount": 75 }
]

The before/after view confirms that only the intended document was modified. Test your filter carefully before running updates on production data.

Testing $unwind with Arrays

Flatten an array field to process each element separately:

// Sample data
[
  { "_id": 1, "product": "Laptop", "tags": ["electronics", "computers", "portable"] },
  { "_id": 2, "product": "Desk", "tags": ["furniture", "office"] }
]

// Pipeline
[{ "$unwind": "$tags" }]

// Result — one document per tag
[
  { "_id": 1, "product": "Laptop", "tags": "electronics" },
  { "_id": 1, "product": "Laptop", "tags": "computers" },
  { "_id": 1, "product": "Laptop", "tags": "portable" },
  { "_id": 2, "product": "Desk", "tags": "furniture" },
  { "_id": 2, "product": "Desk", "tags": "office" }
]

Index Performance Simulation

The tester identifies queries that would benefit from an index:

// Query on a non-indexed field with 10,000 sample documents
{ "email": "alice@example.com" }

// Tester output:
Query plan: COLLSCAN (full collection scan)
Documents examined: 10,000
Documents returned: 1
Performance warning: This query scans the entire collection.

Suggested index:
db.users.createIndex({ email: 1 }, { unique: true })

With index — estimated plan: IXSCAN
Documents examined: 1
Documents returned: 1

Testing $project to Shape Output

Select only specific fields in the query result:

// Query with projection
db.users.find(
  { "role": "user" },
  { "name": 1, "email": 1, "_id": 0 }
)

// Result — only name and email, no _id
[
  { "name": "Bob", "email": "bob@example.com" },
  { "name": "Carol", "email": "carol@example.com" }
]

Setting a field to 1 includes it, 0 excludes it. You cannot mix inclusions and exclusions except for _id. The tester immediately shows the shaped output so you can verify the projection is correct.

Testing $match Early in a Pipeline

Always place $match as early as possible to reduce documents processed by later stages:

// Inefficient — $group processes all documents
[
  { "$group": { "_id": "$category", "total": { "$sum": "$price" } } },
  { "$match": { "total": { "$gt": 1000 } } }
]

// Efficient — $match filters before $group
[
  { "$match": { "status": "active" } },
  { "$group": { "_id": "$category", "total": { "$sum": "$price" } } },
  { "$match": { "total": { "$gt": 1000 } } }
]

The tester shows document counts after each stage. Moving $match earlier reduces the count going into $group, which is the most expensive stage. This optimization can dramatically improve pipeline performance.

Frequently Asked Questions

Simply enter your data, click the process button, and get instant results. All processing happens in your browser for maximum privacy and security.

Yes! MongoDB Query Tester is completely free to use with no registration required. All processing is done client-side in your browser.

Absolutely! All processing happens locally in your browser. Your data never leaves your device, ensuring complete privacy and security.