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: array selecting null #8899

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

PouchDB find error: array selecting null #8899

SourceR85 opened this issue Mar 30, 2024 · 0 comments

Comments

@SourceR85
Copy link
Contributor

SourceR85 commented Mar 30, 2024

Error when selecting array against null value:

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);
});
     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 (<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)

Probably same root cause as in #8898

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 '{"field":null}' | jq .

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

Output:

{
  "ok": true,
  "id": "1",
  "rev": "1-d092ffa43b2c0bde2d792bf5d6570a2c"
}
{
  "docs": [],
  "bookmark": "nil",
  "warning": "No matching index found, create an index to optimize query time."
}
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