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

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

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • v1.3.15
    • manual
    • None
    • 4
    • true

    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)

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:
                7 years, 36 weeks, 6 days ago