Query & Aggregation
AI-Assisted Queries
Use AI to generate and optimize MongoDB queries
AI-Assisted Queries
BusinessUse AI to generate MongoDB queries and aggregation pipelines from natural language descriptions.
Overview
Describe what you want to find in plain English, and MongoDash will generate the appropriate MongoDB query or aggregation pipeline.
Generating Queries
Open a collection in the Data Explorer
Click the AI Query button
Describe what you want to find, for example:
- "Find all active users created in the last 30 days"
- "Show top 10 products by revenue"
- "Count orders by status"
Review the generated query
Click Run Query or Edit to refine
Example Prompts
Simple Filters
- "Find documents where status is pending"
- "Show users with age greater than 21"
- "Get all orders from last week"
Aggregations
- "Count documents by category"
- "Calculate average price per product type"
- "Sum total revenue by month"
Complex Queries
- "Find users who haven't logged in for 90 days"
- "Show products with inventory below reorder threshold"
- "Get customers with more than 5 orders totaling over $1000"
Pipeline Generation
AI can generate multi-stage aggregation pipelines:
Prompt: "Show monthly revenue trends for the last year"
Generated Pipeline:
[
{
"$match": {
"date": {
"$gte": { "$date": "2023-01-01" }
}
}
},
{
"$group": {
"_id": {
"year": { "$year": "$date" },
"month": { "$month": "$date" }
},
"revenue": { "$sum": "$amount" }
}
},
{
"$sort": { "_id": 1 }
}
]
Query Optimization
AI can suggest optimizations for slow queries:
- Paste your query
- Click Optimize Query
- Review suggestions:
- Index recommendations
- Stage reordering
- Projection improvements
AI suggestions are based on best practices. Always test optimized queries before using in production.
Schema-Aware Generation
AI uses your collection schema to:
- Suggest field names (autocomplete)
- Infer appropriate operators for field types
- Validate field paths in nested documents
- Recommend indexed fields
Refining Generated Queries
If the generated query isn't quite right:
- Click Edit Query
- Modify specific conditions
- Re-run the query
- Save for future use
Best Practices
- Be specific in your prompts - mention field names when possible
- Review generated queries before running on production
- Test with filters on large collections
- Save useful generated queries for reuse