[SERVER-3175] Compound index on objects embedded in array can lead to inconsistent query results Created: 01/Jun/11  Updated: 12/Jul/16  Resolved: 25/Oct/11

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

Type: Bug Priority: Minor - P4
Reporter: Bryon Ross Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

Creating a compound index on fields of objects embedded in an array can change the behavior of queries on those fields. It's easiest to demonstrate this behavior using an example. In the test case below, see that querying using the index produces no results, while the same query using no index produces one result.

Test case:
> db.test.insert({ "_id" : 1, "arr" : [

{ "animal" : "cat", "size" : "small" }

,

{ "animal" : "dog", "size" : "medium" }

]});;
> db.test.ensureIndex(

{ "arr.animal" : 1, "arr.size" : 1 }

);
> db.test.find(

{ "arr.animal" : "cat", "arr.size" : "medium" }

);
> db.test.find(

{ "arr.animal" : "cat", "arr.size" : "medium" }

).hint(

{ "$natural" : 1 }

);
{ "_id" : 1, "arr" : [

{ "animal" : "cat", "size" : "small" }

,

{ "animal" : "dog", "size" : "medium" }

] }



 Comments   
Comment by Bryon Ross [ 24/Oct/11 ]

It appears that this issue has been fixed in 2.0.

Generated at Thu Feb 08 03:02:17 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.