[SERVER-1339] updates with $ miss some index updates WAS: Wrong entries returned if same property name used twice in a document Created: 01/Jul/10  Updated: 12/Jul/16  Resolved: 01/Jul/10

Status: Closed
Project: Core Server
Component/s: Index Maintenance, Write Ops
Affects Version/s: 1.4.4, 1.5.3
Fix Version/s: 1.5.4

Type: Bug Priority: Major - P3
Reporter: Niko Sams Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Debian Linux 32-Bit


Operating System: ALL
Participants:

 Description   

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.



 Comments   
Comment by auto [ 01/Jul/10 ]

Author:

{'login': 'erh', 'name': 'Eliot Horowitz', 'email': 'eliot@10gen.com'}

Message: fix $ update with indexes in some cases SERVER-1339
http://github.com/mongodb/mongo/commit/c2aa43941528b581d61e1b8ab8217ed3e657fed0

Generated at Thu Feb 08 02:56:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.