[SERVER-14799] Count with hint doesn't work when hint is a document Created: 06/Aug/14  Updated: 11/Mar/15  Resolved: 11/Sep/14

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.6.3, 2.7.4
Fix Version/s: 2.6.6, 2.7.7

Type: Bug Priority: Major - P3
Reporter: Ross Lawley Assignee: David Storch
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by DOCS-4391 Cannot use the document representing ... Closed
Duplicate
is duplicated by SERVER-16945 cannot specify index when count command Closed
Related
related to SERVER-2677 Allow count to work with query hints Closed
Tested
Operating System: ALL
Backport Completed:
Steps To Reproduce:

t = db.jstests_count_hint;
t.drop();
 
t.save( { i: 1 } );
t.save( { i: 2 } );
assert.eq( 2, t.find().count() );
 
// create a sparse index which should have no entries
t.ensureIndex( { x:1 }, { sparse:true } );
 
assert.eq( 0, t.find( { i: 1 } ).hint( "x_1" ).count(), "A" );
assert.eq( 0, t.find( { i: 1 } ).hint( {x: 1} ).length(), "B" ); // With just find works
assert.eq( 0, t.find( { i: 1 } ).hint( {x: 1} ).count(), "C" ); // Fails

Participants:

 Description   

When using hint() with count() it only works with the string name of the index and not a document representing the index key.



 Comments   
Comment by Githook User [ 21/Nov/14 ]

Author:

{u'username': u'dstorch', u'name': u'David Storch', u'email': u'david.storch@10gen.com'}

Message: SERVER-14799 fix mistake in hint for count patch
Branch: v2.6
https://github.com/mongodb/mongo/commit/b389ee1eedcc84dc9bc08d90145d88c837fa27b7

Comment by Githook User [ 20/Nov/14 ]

Author:

{u'username': u'dstorch', u'name': u'David Storch', u'email': u'david.storch@10gen.com'}

Message: SERVER-14799 hint for a count allows hint to be specified as a document
Branch: v2.6
https://github.com/mongodb/mongo/commit/903b0e905c80b4a2864cb5e05c11c5565b1f19f9

Comment by Githook User [ 11/Sep/14 ]

Author:

{u'username': u'dstorch', u'name': u'David Storch', u'email': u'david.storch@10gen.com'}

Message: SERVER-14799 hint for a count allows hint to be specified as a document
Branch: master
https://github.com/mongodb/mongo/commit/e27b158000b01fe4c505961fefe5a77efbfe8a3e

Comment by Tyler Brock [ 09/Sep/14 ]

Cool, thanks David. Can we schedule this one for 2.7.x or does it still need triage?

Comment by Tyler Brock [ 09/Sep/14 ]

Not accepting a document index description makes it very hard to work with this feature in the C++ driver.

All of our hinting is done through a Query class which wants to take a BSONObj or something that looks like json (so that we can validate a bit).

Being required to use an index name requires that the function just take a string instead of a JSON-ish.

Comment by Githook User [ 12/Aug/14 ]

Author:

{u'username': u'rozza', u'name': u'Ross Lawley', u'email': u'ross.lawley@gmail.com'}

Message: Update driver-count-hint.rst

Clarification re SERVER-14799
Branch: master
https://github.com/10gen/specifications/commit/2043c701e58c8ecdcb4a4ad8c0c5e6c96dacbb63

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