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)
- depends on
-
SERVER-14799 Count with hint doesn't work when hint is a document
- Closed