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

count() on a find() returns scanned count instead of result count

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.0.1
    • Component/s: Querying
    • Environment:
      Ubuntu 11.04, Linux bs-linux64.10gen.cc 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_41
    • Linux

      On a largeish collection, results from count() applied to a query appear to return the number of scanned objects instead of the number of objects returned by the find():

      db.activity.findOne(

      {'datacache.user.id': null}

      )
      null

      > db.activity.find(

      {'datacache.user.id': null}

      )
      (No result)

      > db.activity.find(

      {'datacache.user.id': null}

      ).count()
      816

      > db.activity.count(

      {'datacache.user.id': null}

      )
      816

      > db.activity.find(

      {'datacache.user.id': null}

      ).explain()
      {
      "cursor" : "BtreeCursor datacache_user_id_1",
      "nscanned" : 816,
      "nscannedObjects" : 816,
      "n" : 0,
      "millis" : 44,
      "nYields" : 0,
      "nChunkSkips" : 0,
      "isMultiKey" : true,
      "indexOnly" : false,
      "indexBounds" :

      { "datacache.user.id" : [ [ null, null ] ] }

      }

      Searching for values besides null in that collection is inconclusive: result count always matches scanned count in such cases, they only differ for null.

            Assignee:
            aaron Aaron Staple
            Reporter:
            fgm@osinet.fr Frédéric G. MARAND
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: