PouchDB find error: array selecting null
- Dominant language
- JavaScript
- Stars
- 17.6k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
Error when selecting array against `null` value:
```javascript
it("should not throw", async () => {
const db = context.db;
await db.put({ _id: '1', field: null });
// FIXME: exception is thrown if documents field is `null`
// and selector contains an array
const resp = await db.find({
selector: { field: ["what"] }
});
resp.docs.should.have.length(0);
});
```
```console
TypeError: Cannot read properties of null (reading '0')
at getFieldFromDoc (packages/node_modules/pouchdb-selector-core/lib/index.js:14:18)
at packages/node_modules/pouchdb-selector-core/lib/index.js:434:32
at Array.every ()
at matchSelector (packages/node_modules/pouchdb-selector-core/lib/index.js:417:33)
at packages/node_modules/pouchdb-selector-core/lib/index.js:405:12
at Array.every ()
at rowFilter (packages/node_modules/pouchdb-selector-core/lib/index.js:397:25)
at packages/node_modules/pouchdb-selector-core/lib/index.js:374:12
at Array.filter ()
at Object.filterInMemoryFields (packages/node_modules/pouchdb-selector-core/lib/index.js:373:15)
at packages/node_modules/pouchdb-find/lib/index.js:1454:40
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
```
Probably same root cause as in https://github.com/pouchdb/pouchdb/issues/8898
With CouchDB 3.1.2 (same used in GH CI workflows):
```bash
# database connection
db=http://admin:password@localhost:5984/test
# write document
curl -s -H "Content-Type: application/json" -X PUT $db/1 -d '{"field":null}' | jq .
# query database
curl -s -H "Content-Type: application/json" -X POST $db/_find -d '{"selector":{ "field":["what"] }}' | jq .
```
Output:
```console
{
"ok": true,
"id": "1",
"rev": "1-d092ffa43b2c0bde2d792bf5d6570a2c"
}
{
"docs": [],
"bookmark": "nil",
"warning": "No matching index found, create an index to optimize query time."
}
```
Contributor guide
Assessment
This issue has not been assessed yet.