Database / CouchDB Interview Questions
What are the query operators available in the Mango selector syntax?
Mango selectors are JSON objects where each key is a document field or a Mango operator. Operators begin with $. They fall into four groups: comparison, logical, element, and array operators.
POST /mydb/_find
{
"selector": {
"$and": [
{ "type": { "$eq": "product" } },
{ "price": { "$gte": 10, "$lte": 100 } },
{ "tags": { "$elemMatch": { "$eq": "sale" } } },
{ "discontinued": { "$exists": false } },
{ "name": { "$regex": "^Widget" } }
]
}
}
| Category | Operators | Description |
|---|---|---|
| Comparison | $eq, $ne, $lt, $lte, $gt, $gte | Equality and range comparisons |
| Logical | $and, $or, $not, $nor | Boolean combinations of conditions |
| Element | $exists, $type | Check field presence or JSON type |
| Array | $in, $nin, $all, $elemMatch, $size | Match values in or against arrays |
| Evaluation | $regex, $mod | Regex match; modulo arithmetic |
Important constraints: $regex queries do not use B-tree json indexes — they require a full-text (Lucene) index or fall back to a full scan. Compound conditions using $and can use a json index if all fields in the index prefix are covered by equality conditions. For best performance, structure selectors so the most selective equality conditions come first and match the leading fields of a json index.
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...
