Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-8447

$query with count and $hint not behaving the same as count() and hint() of cursor

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.2.2, 2.2.3
    • Component/s: Querying
    • None
    • Environment:
      OSX, Linux
    • ALL
    • Hide

      in mongo shell, Doing this

      db.listing.find(

      {'p_key': 'DhpPsG'}

      ).count()

      and

      db.listing.find({'$query': {'p_key': 'DhpPsG'}}).count()

      has different result. The former gives result of 1313 while the latter gives 0.

      --------

      Same as for $hint and hint(). Doing this

      db.listing.find({'$min':

      {'_id': '5301fc8327f4f0578d70b24ff6bcc8dd', 'created_on': ISODate("2012-12-26T05:14:35.834Z")}

      , '$query': {'p_key': 'DhpPsG'}}).hint(

      {'p_key': 1}

      ).sort([("created_on", 1), ("_id", 1)]).explain()

      uses the index as I expected but doing this

      db.listing.find({'$min':

      {'_id': '5301fc8327f4f0578d70b24ff6bcc8dd', 'created_on': ISODate("2012-12-26T05:14:35.834Z")}

      , '$query':

      {'p_key': 'DhpPsG'}

      , '$hint':{'p_key': 1}}).sort([("created_on", 1), ("_id", 1)]).explain()

      does not use the index as I expected.

      The result of former is:
      {
      "cursor" : "BtreeCursor p_key_1",
      "isMultiKey" : false,
      "n" : 0,
      "nscannedObjects" : 83260,
      "nscanned" : 83260,
      "nscannedObjectsAllPlans" : 83260,
      "nscannedAllPlans" : 83260,
      "scanAndOrder" : false,
      "indexOnly" : false,
      "nYields" : 0,
      "nChunkSkips" : 0,
      "millis" : 379,
      "indexBounds" : {
      "p_key" : [
      [

      { "$minElement" : 1 }

      ,

      { "$maxElement" : 1 }

      ]
      ]
      },
      "server" : "mbp.local:27017"
      }

      the result of latter is:
      {
      "cursor" : "BasicCursor",
      "isMultiKey" : false,
      "n" : 0,
      "nscannedObjects" : 83260,
      "nscanned" : 83260,
      "nscannedObjectsAllPlans" : 83260,
      "nscannedAllPlans" : 83260,
      "scanAndOrder" : false,
      "indexOnly" : false,
      "nYields" : 1,
      "nChunkSkips" : 0,
      "millis" : 620,
      "indexBounds" : {

      },
      "server" : "mbp.local:27017"
      }

      Show
      in mongo shell, Doing this db.listing.find( {'p_key': 'DhpPsG'} ).count() and db.listing.find({'$query': {'p_key': 'DhpPsG'}}).count() has different result. The former gives result of 1313 while the latter gives 0. -------- Same as for $hint and hint(). Doing this db.listing.find({'$min': {'_id': '5301fc8327f4f0578d70b24ff6bcc8dd', 'created_on': ISODate("2012-12-26T05:14:35.834Z")} , '$query': {'p_key': 'DhpPsG'}}).hint( {'p_key': 1} ).sort( [("created_on", 1), ("_id", 1)] ).explain() uses the index as I expected but doing this db.listing.find({'$min': {'_id': '5301fc8327f4f0578d70b24ff6bcc8dd', 'created_on': ISODate("2012-12-26T05:14:35.834Z")} , '$query': {'p_key': 'DhpPsG'} , '$hint':{'p_key': 1}}).sort( [("created_on", 1), ("_id", 1)] ).explain() does not use the index as I expected. The result of former is: { "cursor" : "BtreeCursor p_key_1", "isMultiKey" : false, "n" : 0, "nscannedObjects" : 83260, "nscanned" : 83260, "nscannedObjectsAllPlans" : 83260, "nscannedAllPlans" : 83260, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 0, "nChunkSkips" : 0, "millis" : 379, "indexBounds" : { "p_key" : [ [ { "$minElement" : 1 } , { "$maxElement" : 1 } ] ] }, "server" : "mbp.local:27017" } the result of latter is: { "cursor" : "BasicCursor", "isMultiKey" : false, "n" : 0, "nscannedObjects" : 83260, "nscanned" : 83260, "nscannedObjectsAllPlans" : 83260, "nscannedAllPlans" : 83260, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 1, "nChunkSkips" : 0, "millis" : 620, "indexBounds" : { }, "server" : "mbp.local:27017" }

      find({'$query':{...}}).count() has different result as find(

      {...}

      ).count()

      Same as for

      and $hint not behaving the same as count() and hint() of cursor

            Assignee:
            Unassigned Unassigned
            Reporter:
            cheewee.khoo@tisproperty.com Chee-Wee
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: