[SERVER-5807] Query doesn't process correctly advanced queries on Multikeys index Created: 10/May/12  Updated: 09/Jul/16  Resolved: 10/May/12

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

Type: Bug Priority: Major - P3
Reporter: Laurent 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   

The lookups index has been set as explained in http://www.mongodb.org/display/DOCS/Using+Multikeys+to+Simulate+a+Large+Number+of+Indexes

The following query doesn't return any value
Query condition: { "_lookups" : { "state" :

{ "$in" : ["Active", "Verified"] }

} }
Explain:
{ "cursor" : "BtreeCursor lookups", "nscanned" : 0, "nscannedObjects" : 0, "n" : 0, "millis" : 0, "nYields" : 0, "nChunkSkips" : 0, "isMultiKey" : true, "indexOnly" : false, "indexBounds" : { "_lookups" : [[{ "state" :

{ "$in" : ["Active", "Verified"] }

}, { "state" :

{ "$in" : ["Active", "Verified"] }

}]] } }

While
Query condition: { "$or" : [{ "_lookups" :

{ "state" : "Active" }

}, { "_lookups" :

{ "state" : "Verified" }

}] }
Explain: { "cursor" : "BtreeCursor lookups", "nscanned" : 10, "nscannedObjects" : 10, "n" : 10, "millis" : 0, "nYields" : 0, "nChunkSkips" : 0, "isMultiKey" : true, "indexOnly" : false, "indexBounds" : { "_lookups" : [[

{ "state" : "Active" }

,

{ "state" : "Active" }

]] } }

works



 Comments   
Comment by Laurent [ 10/May/12 ]

Thanks, you right it was in the doc but not very clearly define. It works now.

Comment by Scott Hernandez (Inactive) [ 10/May/12 ]

Your first query is incorrect. It states that you are looking for an element equal to the document "{state:{ $in: ...}}" as described here: http://www.mongodb.org/display/DOCS/Indexes#Indexes-UsingDocumentsasKeys

If you want the first query to work you would need to use the correct for with $in, which moves the $in query operator after the field (_lookups):

{ "_lookups" : {$in : [

{ "state" : "Active"}

,

{ "state" : "Verified"}

] }}

We'll cleanup the docs to make this a little more clear.

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