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

Inconsistent behaviour for $exists: false and $type: 10 in query

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.9.1
    • Affects Version/s: 1.6.1, 1.6.2, 1.7.0
    • Component/s: Querying
    • Labels:
      None
    • Environment:
      Tested as bogus in macosx 10.6.4 server 64bit and Ubuntu 9.10 64bit
    • ALL

      key: {$exists: false} / key: {$type: 10} / key: null quering gives inconsistent and unpredictable behaviour, so to workraound needed to implement querying of this kind of parameters

      shell script example:
      db.testcollection.ensureIndex(

      {date: -1, country_code: 1, user_id: 1}

      ,

      {unique: 1, background: 1}

      );
      db.testcollection.insert(

      { date: new Date("08/27/2010"), tot_visit: 100}

      );
      db.testcollection.insert(

      { date: new Date("08/27/2010"), country_code: "IT", tot_visit: 77}

      );
      db.testcollection.insert(

      { date: new Date("08/27/2010"), country_code: "ES", tot_visit: 23}

      );
      db.testcollection.insert(

      { date: new Date("08/27/2010"), country_code: "ES", user_id: "and...@spacca.org", tot_visit: 11}

      );
      db.testcollection.insert(

      { date: new Date("08/27/2010"), country_code: "ES", user_id: "andrea.spa...@gmail.com", tot_visit: 5}

      );
      db.testcollection.insert(

      { date: new Date("08/27/2010"), country_code: "ES", user_id: "andrea.spa...@progloedizioni.com", tot_visit: 7}

      );

      db.testcollection.find(

      {date: new Date("08/27/2010")}

      ).count(); // 6 [OK]
      db.testcollection.find({date: new Date("08/27/2010"), country_code: {$exists: true}}).count(); // 5 [OK]
      db.testcollection.find({date: new Date("08/27/2010"), country_code: {$exists: false}}).count(); // 1 [OK]
      db.testcollection.find({date: new Date("08/27/2010"), country_code: {$type: 10}}).count(); // 1 [OK]
      db.testcollection.find(

      {date: new Date("08/27/2010"), country_code: null}

      ).count(); // 1 [OK]
      db.testcollection.find({date: new Date("08/27/2010"), country_code: {$exists: true}, user_id: {$exists: true}}).count(); // 3 [OK]
      db.testcollection.find({date: new Date("08/27/2010"), country_code: {$exists: true}, user_id: {$exists: false}}).count(); // 2 [OK]
      db.testcollection.find({date: new Date("08/27/2010"), country_code: {$exists: true}, user_id: {$type: 10}}).count(); // 0 [??]
      db.testcollection.find({date: new Date("08/27/2010"), country_code: {$exists: true}, user_id: null}).count(); // 2 [OK]

      changing the order of key querying or indexing produces slightly different results, always bogus

            Assignee:
            aaron Aaron Staple
            Reporter:
            aspacca Andrea Spacca
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: