brucearctor opened a new pull request, #9199:
URL: https://github.com/apache/pouchdb/pull/9199

   ## Summary
   
   Fixes #9183.
   
   When performing a `find()` query that uses an index, if one of the documents 
in the database is **missing the indexed field**, `filterInclusiveStart` throws 
a `TypeError: can't convert null to object` from inside `pouchdb-collate`.
   
   ## Root Cause
   
   `filterInclusiveStart` calls `getKeyFromDoc` to extract the indexed key from 
each document. When a document doesn't have the indexed field, `getKeyFromDoc` 
returns `undefined` for that field. This `undefined` value is then passed to 
`collate()`, which crashes.
   
   ## Fix
   
   Added a guard in `filterInclusiveStart` to skip any document whose key is 
`undefined` (i.e. the document is missing the indexed field). This matches 
standard CouchDB behaviour, where documents missing a field are excluded from 
an index.
   
   ## Testing
   
   Added a regression test in `tests/find/test-issues/test.issue9183.js` that 
inserts two documents (one with the indexed field, one without) and verifies 
that querying with the index does not throw and returns only the matching 
document.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to