"$all" query returns less results than an equivalent "$elemMatch" query
- Dominant language
- Erlang
- Stars
- 7k
- Forks
- 1.1k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 9
Description
## Description
We have a database containing only a few hundred records, each with a few dozen fields, usually with multiple attachments. We noticed that some queries were behaving strangely, and narrowed the problem down to the "$all" operator. The following two Mango queries, by my understanding, should produce the exact same results:
```json
{
"selector": {
"number_array_field": {
"$all": [
602
]
}
}
}
```
```json
{
"selector": {
"number_array_field": {
"$elemMatch": {
"$eq": 602
}
}
}
}
```
However, the query with "$all" actually returns less than half the results, missing documents that very obviously contain the number in the array field. (We of course don't always use queries with only a single argument for "$all", but this was the scenario where the issue was discovered.)
## Steps to Reproduce
I tried creating a test database for reproducing the issue, but unfortunately the "$all" query works fine with simpler test data. While I of course can't provide a copy of our production DB, I can run further queries on it if it helps to narrow down the problem.
## Expected Behaviour
The "$all" operator should return all records which contain the given number as part of the array field.
## Your Environment
* CouchDB version used: Issue appears both on 3.2.0 and 3.1.0
* Browser name and version: Tested on Vivaldi (Chrome-based)
* Operating system and version: Linux VM
Contributor guide
Research direction
No implementation files or tests are named. Start by reproducing the equivalent Mango queries against CouchDB 3.1.0 or 3.2.0 with array data that triggers the discrepancy, then compare their result sets; done means "$all" returns every document matched by the equivalent "$elemMatch" query.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- erlang
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100