Database / CouchDB Interview Questions
What is the Mango query language in CouchDB and how does it differ from MapReduce views?
Mango is CouchDB's declarative, MongoDB-inspired query language introduced in CouchDB 2.0. Instead of writing JavaScript map functions, you POST a JSON selector document to the _find endpoint. CouchDB evaluates the selector against a Mango index (or falls back to a full scan) and returns matching documents.
POST /mydb/_find
{
"selector": {
"type": "order",
"status": "pending",
"total": { "$gt": 100 }
},
"fields": ["_id", "customer_id", "total", "created_at"],
"sort": [{ "created_at": "desc" }],
"limit": 20,
"skip": 0
}
Key differences between Mango and MapReduce views:
| Aspect | Mango (_find) | MapReduce Views |
|---|---|---|
| Syntax | JSON selector — no JavaScript required | JavaScript map/reduce functions |
| Primary use | Ad-hoc filtering and sorting on arbitrary fields | Pre-aggregated sorted indexes; efficient range queries |
| Aggregation | No built-in aggregation; returns documents | Yes — _sum, _count, _stats reduce functions |
| Index type | Mango JSON index or full-text index | Persistent sorted B-tree |
| Fallback without index | Full database scan (slow — avoid in production) | N/A — view always has an index |
| Best for | Flexible ad-hoc queries, REST APIs, search | Reporting, aggregations, sorted lookups by known key |
Mango is generally the right choice for new applications because it requires no JavaScript and works well for the typical document-filtering use cases. Use MapReduce views when you need server-side aggregation (sums, counts) or must query by a complex compound key with range semantics.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
