Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-31504

Specifying a mix of query operators and exact matches for a field is inconsistent

    • Query Optimization
    • ALL

      Typically, when specifying a field in a query with a mix of operators or exact matches, you will get an error indicating that the operator is unknown. This error is correct in that it would be ambiguous to accept the mixed format when considering how "exact" matches work for values in this syntax.

      Expected error:

      ermbp:26000(mongod-3.4.6) test> db.test.find({"subfield": {"$lt": 5, "a": 1}})
      Error: error: {
        "ok": 0,
        "errmsg": "unknown operator: a",
        "code": 2,
        "codeName": "BadValue"
      }
      

      However, specifying a non-operator key first allows one to bypass this error to get behavior that seems like an exact match where the $ field is including in the keys to match.

      Failing case:

      ermbp:26000(mongod-3.4.6) test> db.test.find({"subfield": {"a": 1, "$lt": 5}})
      Fetched 0 record(s) in 0ms
      

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            eric.daniels@mongodb.com Eric Daniels
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: