Database / CouchDB Interview Questions
What is the _all_docs endpoint in CouchDB and how does it differ from a custom view?
The _all_docs endpoint is a built-in view that CouchDB automatically maintains for every database. It returns all non-deleted documents sorted by their _id (ascending by default). Internally it is backed by the same document B-tree that stores the documents themselves, so it is always up to date with zero additional index maintenance cost.
# Retrieve all documents (just metadata by default)
curl "http://admin:pass@localhost:5984/mydb/_all_docs?limit=10"
# Include full document bodies
curl "http://admin:pass@localhost:5984/mydb/_all_docs?include_docs=true&limit=10"
# Range query by _id prefix (using the collation order of strings)
curl "http://admin:pass@localhost:5984/mydb/_all_docs?startkey=%22order:%22&endkey=%22order:%22&include_docs=true"
# Fetch specific documents by ID (bulk read equivalent to GET on each)
curl -X POST http://admin:pass@localhost:5984/mydb/_all_docs?include_docs=true \
-H "Content-Type: application/json" \
-d '{"keys":["order:001","order:002","user:42"]}'
Differences from a custom view:
_all_docsis always current — no lazy build delay on first access.- It is keyed only by
_id. You cannot query by any other field — for that you need a view or Mango index. - A custom view can emit any key (category, date, compound key) and can aggregate values via reduce.
_all_docscannot. _all_docsincludes design documents; you can filter them out by requestingstartkey="a"(design docs start with_, which sorts before alphabetic characters in CouchDB's collation).
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...
