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

count and find inconsistent when using $not and a regex

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Duplicate
    • Affects Version/s: 2.4.3, 2.4.10
    • Fix Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • Operating System:
      ALL

      Description

      I have a simple collection containing documents with 2 fields each:

      _id (ObjectId),
      query (String)

      There is a single default index on the collection on the _id field.

      Now, when I perform a query like:

      db.collection.find({"query":/value/})

      I get results, as expected.

      However, when I perform a query like:

      db.collection.find({"query":{$not:/iid/}})

      I get no results. Even though

      db.collection.count({"query":{$not:/iid/}})

      returns 11000.

      If I perform a .explain() on the find query, it tells me that it scanned all ~40K objects in the collection and that n is in fact 11000. A db.collection.find(...).count() gives me 11000 as well. A db.collection.find(...).hasNext() gives me false though.

      I've tried this on two separate systems (2.4.10 and 2.4.3) with the exact same result. I've tried $not:

      {/regex/}

      on other databases in the same system and it works fine. So it seems to be related to the data in this specific collection.

      Some example documents (without _id):

      {"query":"iid: \"53dabd72a38933046cbe7290\""},
      {"query":"cbunid: { $ne: null, $in: [ null, null, null, null, null, null, null, null, null, null, null, null, null, null, null ] }" },
      {"query":"_t: \"Collection\", iid: \"534e7d47749cd80b202a8f19\""},
      {"query":"iid: { $in: [ \"536178f2749cd80b2082b394\" ] }" }

      So, here I would expect the query to match the 3rd document. In fact, importing this small test and running the query displays the problem. I've attached a .json file which can be imported with mongoimport --jsonArray.

      The documents were imported using mongoimport from a file containing a jsonArray with the exact amount of documents as were imported into the DB.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: