Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-4391

Cannot use the document representing the index key for the hint() with count()

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • v1.3.15
    • Affects Version/s: None
    • Component/s: manual
    • Labels:
      None

      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)

            Assignee:
            kay.kim@mongodb.com Kay Kim (Inactive)
            Reporter:
            linda.qin@mongodb.com Linda Qin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              9 years, 21 weeks ago