[SERVER-16945] cannot specify index when count command Created: 20/Jan/15  Updated: 24/Jan/15  Resolved: 20/Jan/15

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

Type: Bug Priority: Major - P3
Reporter: Weiping Ye [X] Assignee: David Storch
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-14799 Count with hint doesn't work when hin... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

when i run:
db.releaseTask.find( {userId: 2, webId: 55, releaseTime:

{ $gte: new Date(1421596860000)}

, failReason: { $nin: [ -1, 0 ] }}).hint(

{userId: 1}

).count()



 Comments   
Comment by David Storch [ 20/Jan/15 ]

Hi weiwei5297@gmail.com,

Thanks for the bug report. This appears to be a duplicate of SERVER-14799, which has been fixed in version 2.6.6. The problem should be resolved if you upgrade to the latest stable release. As a workaround, you can provide the index name to .hint() rather than the index key pattern, e.g.:

db.releaseTask.find( {userId: 2, webId: 55, releaseTime: { $gte: new Date(1421596860000)} , failReason: { $nin: [ -1, 0 ] }}).hint("userId_1").count()

In particular, note the syntax .hint("userId_1"). (You may have to replace "userId_1" with whatever the name of your index is.) Let me know if you have any questions.

Best,
Dave

Comment by Weiping Ye [X] [ 20/Jan/15 ]

when i run:
db.releaseTask.find(

{userId: 2, webId: 55, releaseTime: { $gte: new Date(1421596860000)}

, failReason: { $nin: [ -1, 0 ] }}).hint(

{userId: 1}

).count()

i got:
2015-01-21T01:00:39.137+0800 [conn876] command xiaomishu.$cmd command: count { count: "releaseTask", query: { userId: 2.0, webId: 55.0, releaseTime:

{ $gte: new Date(1421596860000) }

, failReason:

{ $nin: [ -1.0, 0.0 ] }

}, hint:

{ userId: 1.0 }

, fields: {} } planSummary: IXSCAN

{ releaseTime: -1.0 }

keyUpdates:0 numYields:0 locks(micros) r:374995 reslen:48 374ms

it seems use wrong index 'releaseTime' instead of 'userId'

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