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

CWI: count on non-wildcard field returns incorrect results when CWI is used

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.0.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Fully Compatible
    • ALL
    • Hide
      function reproduce(coll, indexKeyPattern, doc, filter) {
          coll.drop();
          coll.createIndex(indexKeyPattern);
          coll.insertOne(doc);
          const findCount = coll.find(filter).count();
          const aggregateCount = coll.aggregate([{$match: filter}, {$count: "count"}]).toArray();
          console.log('==============================================');
          console.log(JSON.stringify(doc, null, 2));
          console.log(findCount);
          console.log(JSON.stringify(aggregateCount, null, 2));
      }
      
      const docs = [
          {
              _id: 269,
              obj: {
                  obj: {
                      date: ISODate("2019-06-24T22:40:06.624Z"),
                      obj: {
                          _id: 273,
                          str: 'Zimbabwe Svalbard & Jan Mayen Islands Personal Loan Account',
                          date: null,
                      },
                  }
              }
          },
          {
              _id: 269,
              obj: {
                  obj: {
                      date: ISODate("2019-06-24T22:40:06.624Z"),
                      obj: {
                          _id: 273,
                          str: 'Zimbabwe Svalbard & Jan Mayen Islands Personal Loan Account',
                          date: null,
                          array: null,
                          obj: {
                              _id: 274,
                              str: 'partnerships',
                              date: ISODate("2019-07-24T16:08:45.196Z"),
                              array: [],
                              geoJson: {type: 'Point', coordinates: [Array]},
                              any: 'virtual intangible Chair'
                          }
                      }
                  },
              }
          },
      ];
      
      const indexKeyPattern = {
          'obj.obj.date': -1,
          'obj.obj.obj.$**': -1
      };
      
      const filter = {
          'obj.obj.date': {'$lte': ISODate("2019-10-06T22:12:37.493Z")}
      };
      
      for (const doc of docs) {
          reproduce(db.testColl, indexKeyPattern, doc, filter);
      }
      
      Show
      function reproduce(coll, indexKeyPattern, doc, filter) { coll.drop(); coll.createIndex(indexKeyPattern); coll.insertOne(doc); const findCount = coll.find(filter).count(); const aggregateCount = coll.aggregate([{$match: filter}, {$count: "count" }]).toArray(); console.log( '==============================================' ); console.log(JSON.stringify(doc, null , 2)); console.log(findCount); console.log(JSON.stringify(aggregateCount, null , 2)); } const docs = [ { _id: 269, obj: { obj: { date: ISODate( "2019-06-24T22:40:06.624Z" ), obj: { _id: 273, str: 'Zimbabwe Svalbard & Jan Mayen Islands Personal Loan Account' , date: null , }, } } }, { _id: 269, obj: { obj: { date: ISODate( "2019-06-24T22:40:06.624Z" ), obj: { _id: 273, str: 'Zimbabwe Svalbard & Jan Mayen Islands Personal Loan Account' , date: null , array: null , obj: { _id: 274, str: 'partnerships' , date: ISODate( "2019-07-24T16:08:45.196Z" ), array: [], geoJson: {type: 'Point' , coordinates: [Array]}, any: 'virtual intangible Chair' } } }, } }, ]; const indexKeyPattern = { 'obj.obj.date' : -1, 'obj.obj.obj.$**' : -1 }; const filter = { 'obj.obj.date' : { '$lte' : ISODate( "2019-10-06T22:12:37.493Z" )} }; for ( const doc of docs) { reproduce(db.testColl, indexKeyPattern, doc, filter); }
    • QO 2023-04-03
    • 135

          Assignee:
          alexander.ignatyev@mongodb.com Alexander Ignatyev
          Reporter:
          alexander.ignatyev@mongodb.com Alexander Ignatyev
          Votes:
          0 Vote for this issue
          Watchers:
          4 Start watching this issue

            Created:
            Updated:
            Resolved: