[SERVER-8447] $query with count and $hint not behaving the same as count() and hint() of cursor Created: 04/Feb/13  Updated: 15/Feb/13  Resolved: 04/Feb/13

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

Type: Bug Priority: Major - P3
Reporter: Chee-Wee Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OSX, Linux


Issue Links:
Duplicate
duplicates SERVER-6767 Interpret $query as special so you ca... Closed
Operating System: ALL
Steps To Reproduce:

in mongo shell, Doing this

db.listing.find(

{'p_key': 'DhpPsG'}

).count()

and

db.listing.find({'$query': {'p_key': 'DhpPsG'}}).count()

has different result. The former gives result of 1313 while the latter gives 0.

--------

Same as for $hint and hint(). Doing this

db.listing.find({'$min':

{'_id': '5301fc8327f4f0578d70b24ff6bcc8dd', 'created_on': ISODate("2012-12-26T05:14:35.834Z")}

, '$query': {'p_key': 'DhpPsG'}}).hint(

{'p_key': 1}

).sort([("created_on", 1), ("_id", 1)]).explain()

uses the index as I expected but doing this

db.listing.find({'$min':

{'_id': '5301fc8327f4f0578d70b24ff6bcc8dd', 'created_on': ISODate("2012-12-26T05:14:35.834Z")}

, '$query':

{'p_key': 'DhpPsG'}

, '$hint':{'p_key': 1}}).sort([("created_on", 1), ("_id", 1)]).explain()

does not use the index as I expected.

The result of former is:
{
"cursor" : "BtreeCursor p_key_1",
"isMultiKey" : false,
"n" : 0,
"nscannedObjects" : 83260,
"nscanned" : 83260,
"nscannedObjectsAllPlans" : 83260,
"nscannedAllPlans" : 83260,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 379,
"indexBounds" : {
"p_key" : [
[

{ "$minElement" : 1 }

,

{ "$maxElement" : 1 }

]
]
},
"server" : "mbp.local:27017"
}

the result of latter is:
{
"cursor" : "BasicCursor",
"isMultiKey" : false,
"n" : 0,
"nscannedObjects" : 83260,
"nscanned" : 83260,
"nscannedObjectsAllPlans" : 83260,
"nscannedAllPlans" : 83260,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 1,
"nChunkSkips" : 0,
"millis" : 620,
"indexBounds" : {

},
"server" : "mbp.local:27017"
}

Participants:

 Description   

find({'$query':{...}}).count() has different result as find(

{...}

).count()

Same as for

and $hint not behaving the same as count() and hint() of cursor


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