Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PouchDB find error: selector containing [null] throws by non-matching document #8900

Open
SourceR85 opened this issue Mar 30, 2024 · 0 comments

Comments

@SourceR85
Copy link
Contributor

SourceR85 commented Mar 30, 2024

Error when selecting array containing null against non-existing value:

it("should not throw", async () => {
  const db = context.db;

  await db.put({ _id: '1' });

  // FIXME: exception is thrown if document field not exists
  //        and selector contains a null in an array
  const resp = await db.find({
    selector: { field: [null] }
  })

  resp.docs.should.have.length(0);
});
     TypeError: Cannot read properties of undefined (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 (<anonymous>)
      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 (<anonymous>)
      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 (<anonymous>)
      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)

With CouchDB 3.1.2 (same used in GH CI workflows):

# database connection
db=http://admin:password@localhost:5984/test

# write document
curl -s -H "Content-Type: application/json" -X PUT $db/1 -d '{}' | jq .

# query database
curl -s -H "Content-Type: application/json" -X POST $db/_find -d '{"selector":{ "field":[null] }}' | jq .

Output:

{
  "ok": true,
  "id": "1",
  "rev": "1-967a00dff5e02add41819138abb3284d"
}
{
  "docs": [],
  "bookmark": "nil",
  "warning": "No matching index found, create an index to optimize query time."
}
@SourceR85 SourceR85 changed the title PouchDB find error: selector array containing null didn't match PouchDB find error: selector array containing null didn't match Mar 30, 2024
@SourceR85 SourceR85 changed the title PouchDB find error: selector array containing null didn't match PouchDB find error: selector containing [null] throws by non-matching document Mar 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant