[SERVER-1040] positional operator and $set with an indexed field, update fails with error: can't append to array using string field name Created: 21/Apr/10  Updated: 07/Mar/14  Resolved: 16/Aug/10

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

Type: Bug Priority: Major - P3
Reporter: michael haraburda Assignee: Aaron Staple
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

win7 x64


Participants:

 Description   

Wed Apr 21 22:34:00 Mongo DB : starting : pid = 0 port = 27333 dbpath = d:/mongodb/data master = 0 slave = 0 64-bit
****
WARNING: This is development version of MongoDB. Not recommended for production.
****
Wed Apr 21 22:34:00 db version v1.5.1-pre-, pdfile version 4.5
Wed Apr 21 22:34:00 git version: f528f30c4fb604600f24d227c1c57e5c7bbfd191
Wed Apr 21 22:34:00 sys info: windows (6, 0, 6002, 2, 'Service Pack 2') BOOST_LIB_VERSION=1_39

> db.test.drop()
true
> db.test.insert({a: [

{id: 1, x: [5,6,7]}

,

{id: 2, x: [8,9,10]}

]})
> db.test.update(

{'a.id': 1}

, {$set: {'a.$.x': [1,1,1]}})
> db.test.find()
{ "_id" : ObjectId("4bcfc3e47c39000000001d80"), "a" : [

{ "id" : 1, "x" : [ 1, 1, 1 ] }

,

{ "id" : 2, "x" : [ 8, 9, 10 ] }

] }
> db.test.ensureIndex(

{'a.id': 1}

)
> db.test.update(

{'a.id': 1}

, {$set: {'a.$.x': [1,2,2]}})
can't append to array using string field name
> db.test.dropIndex(

{'a.id': 1}

)

{ "nIndexesWas" : 2, "ok" : 1 }

> db.test.update(

{'a.id': 1}

, {$set: {'a.$.x': [6,6,7]}})
> db.test.find()
{ "_id" : ObjectId("4bcfc3e47c39000000001d80"), "a" : [

{ "id" : 1, "x" : [ 6, 6, 7 ] }

,

{ "id" : 2, "x" : [ 8, 9, 10 ] }

] }
>



 Comments   
Comment by michael haraburda [ 19/Aug/10 ]

I can confirm it works for me now as well after an upgrade to the latest... thanks.

Comment by auto [ 16/Aug/10 ]

Author:

{'login': 'astaple', 'name': 'Aaron', 'email': 'aaron@10gen.com'}

Message: SERVER-1040 add test
http://github.com/mongodb/mongo/commit/4d7319d82fe11cf9b79b06e931ac68bf550576f5

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