[SERVER-42277] MongoDB ignores some hint'ed queries on array fiels (e.g., array: {$gt: [10]}) in v2.2.3 Created: 18/Jul/19  Updated: 06/Dec/22  Resolved: 22/Jul/19

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

Type: Bug Priority: Minor - P4
Reporter: João Agnelo Assignee: Backlog - Triage Team
Resolution: Incomplete Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Server Triage
Operating System: ALL
Participants:

 Description   

While performing an academic experiment based on the random generation of a large set of tests to exercise the Query Language of MongoDB (all of which syntactically valid), a possible bug was detected in some preliminary trial tests.

Comparing an array field to an array of values (e.g., {$gt: ["a", "b"] or ["a"]}) instead of a single value (e.g., "a" or "b") on a hint()'ed query returns erroneous results.

  • hint()'ing on the _id field (with or without creating a custom index with ensureIndex) returns results but cursor.count() and cursor.size() both return 0.
  • hint()'ing on a custom index returns no results and cursor.count() and cursor.size() both return 0.
  • without hint()'ing but with the custom index created no results are returned and cursor.count() and cursor.size() both return 0.
  • the same query but without hint()'ing and with no custom indexes created results in the array portion of the query being ignored.

Examples:

find($and: [{array: {$gt: [10]}}, {notArray: {$lt: 1000}}]) results in the same as

find({notArray: {$lt: 1000}}) meaning that the array portion of the query is ignored

-------------------------------------------------------------------------------------------

ensureIndex({notArray: 1})

find($and: [{array: {$gt: [10]}}, {notArray: {$lt: 1000}}]) no results and cursor.count() and cursor.size() both return 0

find($and: [{array: {$gt: [10]}}, {notArray: {$lt: 1000}}]).hint("id") shows results in the shell but cursor.count() and cursor.size() both return 0

find($and: [{array: {$gt: [10]}}, {notArray: {$lt: 1000}}]).hint("notArray_1") no results and cursor.count() and cursor.size() both return 0

 

 



 Comments   
Comment by Danny Hatcher (Inactive) [ 22/Jul/19 ]

Due to the old age of this version of MongoDB, I'm going to close this ticket. Please re-open if you are able to reproduce against a modern version.

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