apache / apache/pouchdb

Error querying a view with reduce built-in

Open
#8,614 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
17.6k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

### Issue
I'd like to perform a reduce of an existing view. The view exists and works properly and has no reduce function defined. When I try to call a built-in reduce when querying the view, I get an error.

My view:
```
contacts: {
map: "function (doc) {\n if(doc.type==='contact')\n emit(doc._id, doc.first_name + ' ' + doc.last_name);\n}",
}
```

The query:
```js
await db.query("myView", {reduce:"_count"});
```

The error I get:

error: 'query_parse_error',
reason: 'Invalid boolean parameter: "_count"'

The [documentation](https://pouchdb.com/api.html#query_database) explicitly says:

> options.reduce: Defaults to true when a reduce function is defined, or false otherwise. Valid values:
> * true - calls the defined reduce function, or the map function if no reduce is defined.
> * false - calls the defined map function.
> * A reduce function.
> * **The string name of a built-in function: '_sum', '_count', or '_stats'.**

Either it's a bug or the documentation is misleading...

### Info
- Environment: Node.js
- Adapter: Direct calls to CouchDB
- Server: CouchDB

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.