[SERVER-1155] Update with positional operator with regex selector fails Created: 25/May/10  Updated: 12/Jul/16  Resolved: 02/Oct/13

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 1.4.4
Fix Version/s: 2.5.3

Type: Bug Priority: Major - P3
Reporter: Okku Touronen Assignee: Andrew Morrow (Inactive)
Resolution: Done Votes: 3
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Win 7 64bit


Issue Links:
Related
related to SERVER-14280 Additional tests for updates with reg... Closed
is related to SERVER-9028 Using positional operator with db.col... Closed
Participants:

 Description   

> db.t3.insert({_id:1,list:[

{name:"a",val:1}

]})
> db.t3.find()
{ "_id" : 1, "list" : [

{ "name" : "a", "val" : 1 }

] }
> db.t3.update(

{ "list.name" : /^a$/ }

,{ $set:

{ "list.$.val" : 2 }

},false,true)
can't append to array using string field name

> db.t3.update(

{ "list.name" : "a" }

,{ $set:

{ "list.$.val" : 2 }

},false,true)
> db.t3.find()
{ "_id" : 1, "list" : [

{ "name" : "a", "val" : 2 }

] }
>



 Comments   
Comment by Scott Hernandez (Inactive) [ 02/Oct/13 ]

Fixed in code refactoring for 2.5.3:

> db.t3.insert({_id:1,list:[
... {name:"a",val:1}
... ]})
> db.t3.update(
... { "list.name" : /^a$/ }
... ,{ $set:
... { "list.$.val" : 2 }
... },false,true)
> db.t3.find()
{ "_id" : 1, "list" : [  {  "name" : "a",  "val" : 2 } ] }

Comment by Arkadiy Kukarkin [ 25/Apr/13 ]

This is still broken in 2.4.3, now fails with:

data:PRIMARY> db.foo.update(

{ 'list.prop' : /blah/ }

, { $unset :

{ 'list.$.prop' : true }

} );
Cannot apply the positional operator without a corresponding query field containing an array.

data:PRIMARY> db.foo.update(

{ 'list.prop' : "blah" }

, { $unset :

{ 'list.$.prop' : true }

} );
// works correctly

Comment by Ronald Stalder [ 07/Apr/13 ]

Workaround:

> db.t3.update({ "list" : {$elemMatch:

{name: /^a$/ }

}},{ $set:

{ "list.$.val" : 3 }

},false,true)
> db.t3.find()
{ "_id" : 1, "list" : [

{ "name" : "a", "val" : 3 }

] }

Comment by Arkadiy Kukarkin [ 24/Oct/12 ]

Confirmed still broken in 2.0.5 and likely 2.2.0 on Ubunu 12.04 x86_64, fails with

can't append to array using string field name [$]

This is a pretty major bug, looks like regex match doesn't mark the element as 'matched'?

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