Natural Language Queries

Agent M's AI understands natural language, making MongoDB queries accessible to everyone. Learn how to communicate effectively with AI to get the results you need.

How It Works

Instead of writing MongoDB syntax like:

db.users.find({age: {$gte: 18}, city: "New York"})

You can simply say:

"Show me all users who are 18 or older and live in New York"

The AI translates your natural language into proper MongoDB queries and explains what it does.

Basic Query Patterns

The beauty of Agent M lies in how it translates your natural language into MongoDB queries. When you want to find documents, you can start simple with "Show me all users" and the AI creates db.users.find() to return all documents in the users collection.

Counting and Aggregation

When you need to count documents, simply ask "How many products do we have?" and the AI creates db.products.countDocuments() to return the total number of products.

Sorting and Limiting

Sort Results

  • You say: "Show me the most expensive products"
  • AI creates: db.products.find().sort({price: -1})
  • Result: Products sorted by price (highest first)

Limit Results

  • You say: "Get the top 10 users by registration date"
  • AI creates: db.users.find().sort({createdAt: -1}).limit(10)
  • Result: 10 most recently registered users

Advanced Query Patterns

Date and Time Queries

Recent Data

  • You say: "Show me orders from the last 7 days"
  • Result: Orders from the past week

Date Range

  • You say: "Find users registered between January and March"
  • Result: Users registered in Q1

Text Search

Contains Text

  • You say: "Find products with 'laptop' in the name"
  • Result: Products with "laptop" in the name

Exact Match

  • You say: "Get users with email ending in @gmail.com"
  • Result: Users with Gmail addresses

Tips for Better Queries

Be Specific and Clear

❌ Vague

"Show me some data"

✅ Specific

"Show me all users who registered in the last 30 days"

Mention Collection Names

❌ Ambiguous

"Find products with high ratings"

✅ Clear

"Find products in the catalog collection with rating above 4.5"

Next Steps