CouchDB `_find` api `$elemMatch` fails to find matching record

14 views Asked by At

I have a CouchDB database contains arrays of mixed numbers of subject age, something like age: [20, 30, "n/a", 38, 50, "n/a"]. Not all documents have "n/a".

When I apply the below _find parameter to search this database, I found that couchdb fail to return any of the documents with mixed string/number age records, even there are numbers between the search range (such as the above example)

{
  "selector": {
    "age": {
      "$elemMatch": {
        "$and": [
          { "$type": "number" },
          { "$lt": 39 },
          { "$gt": 37 }
        ]
      }
    }
  },
  "fields": ["_id","age"]
}

From the documentation, $elemMatch should Matches and returns all documents that contain an array field with at least one element that matches all the specified query criteria.

I am wondering why my above find command fails to process mixed string/number arrays?

0

There are 0 answers