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

When an index is present, $not operator doesn't return documents that don't contain this field

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Major - P3 Major - P3
    • None
    • None
    • Querying
    • None
    • ALL
    • Hide

      // 1. Insert these 3 rows:
      db.testNotIndex.insert(

      {"date": ISODate("2012-12-21T16:03:08.428Z") }

      )
      db.testNotIndex.insert(

      {"date": ISODate("2012-12-21T17:03:08.428Z") }

      )
      db.testNotIndex.insert(

      {"a": 1 }

      )

      // 2. Without an index, 2 results are returned as expected for 'd'
      var d = ISODate("2012-12-21T17:33:08.428Z");
      var c1 = db.testNotIndex.count({"date": {$not:{$lte:ISODate("2012-12-21T16:33:08.428Z")}} });

      // 3. Using an index, only 1 result is returned when issuing the same query. Documents without the 'date' field are ignored.
      db.testNotIndex.ensureIndex(

      {date: 1}

      )
      var c2 = db.testNotIndex.count({"date": {$not:{$lte:ISODate("2012-12-21T16:33:08.428Z")}} });

      // ( 2 == 1 ) == false
      assert( c1 == c2 );

      Show
      // 1. Insert these 3 rows: db.testNotIndex.insert( {"date": ISODate("2012-12-21T16:03:08.428Z") } ) db.testNotIndex.insert( {"date": ISODate("2012-12-21T17:03:08.428Z") } ) db.testNotIndex.insert( {"a": 1 } ) // 2. Without an index, 2 results are returned as expected for 'd' var d = ISODate("2012-12-21T17:33:08.428Z"); var c1 = db.testNotIndex.count({"date": {$not:{$lte:ISODate("2012-12-21T16:33:08.428Z")}} }); // 3. Using an index, only 1 result is returned when issuing the same query. Documents without the 'date' field are ignored. db.testNotIndex.ensureIndex( {date: 1} ) var c2 = db.testNotIndex.count({"date": {$not:{$lte:ISODate("2012-12-21T16:33:08.428Z")}} }); // ( 2 == 1 ) == false assert( c1 == c2 );

    Description

      When using the $not operator on an indexed 'date' field, only documents that contain this field are returned, while documents that do not contain this field (and should therefore be returned), are ignored.

      Please see steps to reproduce for details.

      Attachments

        Activity

          People

            Unassigned Unassigned
            guyz Guy Zyskind
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: