---
source: https://iinventedlight.com/library/notes/couchdb-mango-indexes.md
title: "CouchDB Mango queries use a custom _index when one exists"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache-2.0 (Apache CouchDB); Apache-2.0 (Apache CouchDB); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Apache CouchDB, /{db}/_find; Apache CouchDB, Mango README. Apache-2.0; Apache-2.0."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-20
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-20
as_of: 2026-11-20
confidence: medium
untested: "Not reproduced (2026-11-20). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: CouchDB Mango indexes"
tags: [couchdb, mango, index, databases]
client: Librarian
sources:
  - id: S1
    title: "/{db}/_find"
    publisher: Apache CouchDB
    url: https://docs.couchdb.org/en/stable/api/database/find.html
    accessed: 2026-11-20
    license: "Apache-2.0"
  - id: S2
    title: "Mango README"
    publisher: Apache CouchDB
    url: https://raw.githubusercontent.com/apache/couchdb/main/src/mango/README.md
    accessed: 2026-11-20
    license: "Apache-2.0"
---
# CouchDB Mango queries use a custom _index when one exists
**Answer:** Queries use custom indexes specified using the `_index` endpoint, if available. If none is available, and the planner allows it, they fall back to the built-in `_all_docs` index, which can be slow.

## _find and _index

- `_find` the POST endpoint that runs the query
- `_index` the endpoint that specifies custom indexes
- `_all_docs` the built-in index used when no custom index is available
- `selector` the JSON object describing criteria used to select documents

Find documents using a declarative JSON querying syntax. The selector is required. A custom index is specified using the _index endpoint.

## Creating indices in Mango

The supported actions cover the four normal CRUD operations, plus one meta action that creates indices on the database. The API adds one URI endpoint onto the existing CouchDB HTTP API. Creating databases, authentication, and Map/Reduce views stay available; other existing behavior is still supported. The general principle is to stay simple for clients, and to give users a more natural conversion to Apache CouchDB.

## See also

- [couchdb-mango-queries](https://iinventedlight.com/library/notes/couchdb-mango-queries/)
- [sqlite-query-planner-indexes](https://iinventedlight.com/library/notes/sqlite-query-planner-indexes/)
- [postgres-indexes-basics](https://iinventedlight.com/library/notes/postgres-indexes-basics/)

## Claims

- id: C1
  claim: Queries use custom indexes created at the _index endpoint when those indexes are available.
  source: S1
  evidence: "Queries will use custom indexes, specified using the _index endpoint, if available."

- id: C2
  claim: Without a usable custom index, a query may use the built-in _all_docs index, which can be arbitrarily slow.
  source: S1
  evidence: "they use the built-in _all_docs index, which can be arbitrarily slow."

- id: C3
  claim: Mango includes a meta action to create indices on the database, alongside the usual document actions.
  source: S2
  evidence: "plus one meta action to create indices on the database."

## Sources

- [S1] /{db}/_find. Apache CouchDB. https://docs.couchdb.org/en/stable/api/database/find.html . License: Apache-2.0. Accessed 2026-11-20.

- [S2] Mango README. Apache CouchDB. https://raw.githubusercontent.com/apache/couchdb/main/src/mango/README.md . License: Apache-2.0. Accessed 2026-11-20.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Apache CouchDB, /{db}/_find; Apache CouchDB, Mango README. Apache-2.0; Apache-2.0. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
