[SERVER-31504] Specifying a mix of query operators and exact matches for a field is inconsistent Created: 10/Oct/17  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Querying
Affects Version/s: 3.4.9
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Eric Daniels (Inactive) Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: mql-semantics, query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Operating System: ALL
Participants:

 Description   

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



 Comments   
Comment by Asya Kamsky [ 23/Nov/17 ]

Should this really be an error? Rather than emulating an exact match, it is an exact match.

This query is for document where "subfield" matches an exact object:

db.test.find({"subfield": {"a": 1, "$lt": 5}})
{ "_id" : ObjectId("5a173835af3c159e9e840c47"), "subfield" : { "a" : 1, "$lt" : 5 } }

Comment by Ramon Fernandez Marina [ 10/Oct/17 ]

I'm able to reproduce this behavior with 3.5.13 as well.

Generated at Thu Feb 08 04:27:16 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.