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

updates with $ miss some index updates WAS: Wrong entries returned if same property name used twice in a document

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.5.4
    • Affects Version/s: 1.4.4, 1.5.3
    • Labels:
      None
    • Environment:
      Debian Linux 32-Bit
    • ALL

      Steps to reproduce:

      //create initial data
      > db.foo.drop();
      > db.foo.insert({abc:

      {visible:true}

      , testarray:[

      {foobar_id:316, visible:true, xxx: 1}

      ]});
      > db.foo.ensureIndex(

      {'abc.visible':1, 'testarray.visible':1, 'testarray.xxx': 1}

      );

      //it is found correctly
      > db.foo.find({'abc.visible':true, testarray:{'$elemMatch':

      {visible:true, xxx:1}

      }});
      { "_id" : ObjectId("4c2c90393a3c2265cd3d1288"), "abc" :

      { "visible" : true }

      , "testarray" : [

      { "foobar_id" : 316, "visible" : true, "xxx" : 1 }

      ] }
      > db.foo.find({testarray:{'$elemMatch':

      {visible:true, xxx:1}

      }});
      { "_id" : ObjectId("4c2c90393a3c2265cd3d1288"), "abc" :

      { "visible" : true }

      , "testarray" : [

      { "foobar_id" : 316, "visible" : true, "xxx" : 1 }

      ] }

      //update the array
      > db.foo.update(

      {'testarray.foobar_id':316}

      , {'$set': {'testarray.$.visible': true, 'testarray.$.xxx': 2}}, false, true);

      //verify it updated correctly
      > db.foo.find();
      { "_id" : ObjectId("4c2c90393a3c2265cd3d1288"), "abc" :

      { "visible" : true }

      , "testarray" : [

      { "foobar_id" : 316, "visible" : true, "xxx" : 2 }

      ] }

      //this find still works
      > db.foo.find({testarray:{'$elemMatch':

      {visible:true, xxx:2}

      }});
      { "_id" : ObjectId("4c2c90393a3c2265cd3d1288"), "abc" :

      { "visible" : true }

      , "testarray" : [

      { "foobar_id" : 316, "visible" : true, "xxx" : 2 }

      ] }

      //here comes the issue, nothing found here
      > db.foo.find({'abc.visible':true, testarray:{'$elemMatch':

      {visible:true, xxx:2}

      }});
      //expected: the one entry created above (as 'avc.visible' is still true)

      just commands for easy copy&paste:
      db.foo.drop();
      db.foo.insert({abc:

      {visible:true}

      , testarray:[

      {foobar_id:316, visible:true, xxx: 1}

      ]});
      db.foo.ensureIndex(

      {'abc.visible':1, 'testarray.visible':1, 'testarray.xxx': 1}

      );
      db.foo.find({'abc.visible':true, testarray:{'$elemMatch':

      {visible:true, xxx:1}

      }});
      db.foo.find({testarray:{'$elemMatch':

      {visible:true, xxx:1}

      }});
      db.foo.update(

      {'testarray.foobar_id':316}

      , {'$set': {'testarray.$.visible': true, 'testarray.$.xxx': 2}}, false, true);
      db.foo.find();
      db.foo.find({testarray:{'$elemMatch':

      {visible:true, xxx:2}

      }});
      db.foo.find({'abc.visible':true, testarray:{'$elemMatch':

      {visible:true, xxx:2}

      }});

      renaming one "visible" property is a workaround.

            Assignee:
            eliot Eliot Horowitz (Inactive)
            Reporter:
            niko.sams Niko Sams
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: