couchdb icon indicating copy to clipboard operation
couchdb copied to clipboard

"$all" query returns less results than an equivalent "$elemMatch" query

Open pip25 opened this issue 4 years ago • 1 comments

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:

{
   "selector": {
      "number_array_field": {
         "$all": [
            602
         ]
      }
   }
}
{
   "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

pip25 avatar Nov 10 '21 21:11 pip25

Hi,

can you give an example dataset, for which both queries gives different results?

big-r81 avatar Feb 09 '22 17:02 big-r81