[SERVER-1095] findandmodify doesn't support positional ($) operator Created: 06/May/10  Updated: 12/Jul/16  Resolved: 11/May/10

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 1.4.2
Fix Version/s: 1.5.2

Type: Bug Priority: Major - P3
Reporter: PowerMeMobile Assignee: Mathias Stearn
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu 9.10 (on VMWare 6.5.1 under Windows 7)


Participants:

 Description   

Please, consider the following use case:
> use foo
switched to db foo
> db.test.insert({ Article : "Bla-bla", TagDesc : [

{Name : "Nature", Rate: 10}

,

{Name: "Culture", Rate : 2 }

] })
> db.runCommand({ findandmodify : "test", query :

{ Article : "Bla-bla", "TagDesc.Rate" : 2 }

, update : { $set :

{ "TagDesc.$.Name" : "Economics" }

} })
{
"value" : {
"_id" : ObjectId("4bda64d1967d194e851b03ed"),
"Article" : "Bla-bla",
"TagDesc" : [

{ "Name" : "Nature", "Rate" : 10 }

,

{ "Name" : "Culture", "Rate" : 2 }

]
},
"ok" : 1
}

server console output:
Fri Apr 30 08:07:36 foo.$cmd Caught Assertion in update , continuing
Fri Apr 30 08:07:36 update foo.test query:

{ _id: ObjId(4bda64d1967d194e851b03ed) }

exception userassert:can't append to array using string field name 0ms

The object was not changed
> db.test.find()
{ "_id" : ObjectId("4bda64d1967d194e851b03ed"), "Article" : "Bla-bla", "TagDesc" : [

{ "Name" : "Nature", "Rate" : 10 }

,

{ "Name" : "Culture", "Rate" : 2 }

] }
>

Note that at this time we specified index of item manually instead of using positional operator ( "TagDesc.$.Name" -> "TagDesc.1.Name" ).
And changes were applied successfully.
> db.runCommand({ findandmodify : "test", query :

{ Article : "Bla-bla", "TagDesc.Rate" : 2 }

, update : { $set :

{ "TagDesc.1.Name" : "Economics" }

} })
{
"value" : {
"_id" : ObjectId("4bda64d1967d194e851b03ed"),
"Article" : "Bla-bla",
"TagDesc" : [

{ "Name" : "Nature", "Rate" : 10 }

,

{ "Name" : "Culture", "Rate" : 2 }

]
},
"ok" : 1
}
> db.test.find()
{ "Article" : "Bla-bla", "TagDesc" : [

{ "Name" : "Nature", "Rate" : 10 }

,

{ "Name" : "Economics", "Rate" : 2 }

], "_id" : ObjectId("4bda64d1967d194e851b03ed") }
>



 Comments   
Comment by auto [ 11/May/10 ]

Author:

{'login': 'RedBeard0531', 'name': 'Mathias Stearn', 'email': 'mathias@10gen.com'}

Message: Support $ positional operator with findAndModify SERVER-1095
http://github.com/mongodb/mongo/commit/101f69cee9113e302fec35d61dd6becbd2b523e8

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