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

$elemMatch w/ positional $ project SBE bug

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Critical - P2
    • Resolution: Fixed
    • 5.2.0, 5.1.0
    • 5.3.0, 5.1.2, 5.2.0-rc1
    • None
    • None
    • Fully Compatible
    • ALL
    • v5.2
    • Hide

      (function() {
          'use strict';
       
      function runTest() {
          db.test.drop();
          db.test.insert({ _id: 1, "states": [{x: 1, y: 1}, {x: 2, y: 2}]});
          let result = db.test.runCommand({find: "test", filter: {_id: 1 , states: {"$elemMatch": {x: 1, "y": {"$exists": true}}}}, projection: {"states.$": 1 }, limit: 1, singleBatch: true});
          assert.eq(result.cursor.firstBatch.length, 1, "firstBatch is empty");
          assert.eq(result.cursor.firstBatch[0].states.length, 1, "states array is empty");
          assert.eq(result.cursor.firstBatch[0].states[0].x, 1, "unexpected 'states' document returned");
      }
       
      printjson("Run test with SBE disabled");
      assert.commandWorked(
          db.adminCommand({setParameter: 1, internalQueryForceClassicEngine: true}));
      runTest();
       
      printjson("Run test with SBE enabled");
      assert.commandWorked(
          db.adminCommand({setParameter: 1, internalQueryForceClassicEngine: false}));
      runTest();
      }());
      

      Show
      (function() { 'use strict';   function runTest() { db.test.drop(); db.test.insert({ _id: 1, "states": [{x: 1, y: 1}, {x: 2, y: 2}]}); let result = db.test.runCommand({find: "test", filter: {_id: 1 , states: {"$elemMatch": {x: 1, "y": {"$exists": true}}}}, projection: {"states.$": 1 }, limit: 1, singleBatch: true}); assert.eq(result.cursor.firstBatch.length, 1, "firstBatch is empty"); assert.eq(result.cursor.firstBatch[0].states.length, 1, "states array is empty"); assert.eq(result.cursor.firstBatch[0].states[0].x, 1, "unexpected 'states' document returned"); }   printjson("Run test with SBE disabled"); assert.commandWorked( db.adminCommand({setParameter: 1, internalQueryForceClassicEngine: true})); runTest();   printjson("Run test with SBE enabled"); assert.commandWorked( db.adminCommand({setParameter: 1, internalQueryForceClassicEngine: false})); runTest(); }());
    • QE 2021-12-13

    Description

      In the above reproduction, the asserts pass with SBE disabled. The first assert in firstBatch.length fails when SBE is enabled.

      Attachments

        Activity

          People

            andrew.paroski@mongodb.com Drew Paroski
            james.wahlin@mongodb.com James Wahlin
            Votes:
            0 Vote for this issue
            Watchers:
            16 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: