[DOCS-4391] Cannot use the document representing the index key for the hint() with count() Created: 19/Nov/14  Updated: 04/Mar/23  Resolved: 05/Dec/14

Status: Closed
Project: Documentation
Component/s: manual
Affects Version/s: None
Fix Version/s: v1.3.15

Type: Bug Priority: Major - P3
Reporter: Linda Qin Assignee: Kay Kim (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-14799 Count with hint doesn't work when hin... Closed
Participants:
Days since reply: 9 years, 10 weeks, 5 days ago

 Description   

MongoDB 2.6 supports the use of hint() with count(). However, due to SERVER-14799, the hint only works with the string name of the index and not a document representing the index key.

Currently the example in the 2.6 docs uses the document representing the index key in the hint, which is not working now.

http://docs.mongodb.org/manual/reference/method/cursor.count/#specify-the-index-to-use

The following operation uses the index { status: 1 } to return a count of the documents in the orders collection with the field ord_dt greater than new Date('01/01/2012') and the status field is equal to "D":

db.orders.find(
   { ord_dt: { $gt: new Date('01/01/2012') }, status: "D" }
).hint( { status: 1 } ).count()

Suggest changing the above to:

The following operation uses the index { status: 1 } (with index name "status_1") to return a count of the documents in the orders collection with the field ord_dt greater than new Date('01/01/2012') and the status field is equal to "D":

db.orders.find(
   { ord_dt: { $gt: new Date('01/01/2012') }, status: "D" }
).hint( "status_1" ).count()

Also, it would be nice to explicitly ask users to use the name of the index in the hint in 2.6. (or at least before SERVER-14799 is backported to 2.6)



 Comments   
Comment by Githook User [ 05/Dec/14 ]

Author:

{u'username': u'kay-kim', u'name': u'kay', u'email': u'kay.kim@10gen.com'}

Message: DOCS-4391 use index name instead of index key spec
Branch: master
https://github.com/mongodb/docs/commit/8adf787d5cb73a92836c9edb26a13fee0302021a

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