1

I'm trying to run a multiple update of a field of an object in an array. The structure is like:

{
rs:[
  {uid:"123", ufc:"bla"},
  {uid:"123", ufc:"foo"}, 
  //...
  ]
}

For some reason only the first field is updated. I read I have to use multi:true to solve this, but it's still the same.

I tried:

db.mycollection.update({"rs.uid": "123"},
                  {$set: {"rs.$.ufc":"test"}},
                  false, true
                  )

And:

db.mycollection.update({"rs.uid": "123"},
                  {$set: {"rs.$.ufc":"test"}},
                  {multi: true}
                  )

Probably related with the nested structure? Thanks.

User
  • 31,811
  • 40
  • 131
  • 232

1 Answers1

2

I think you have hit the same problem as mentioned in this question

. As solution either wait for the following issue to be solved or update array elements one by one. In your query multi means updating multi document not item of any array field. The query works like this: Update all documents which has an item in rs field having uid "123".

Of course as an alternative if possible change structure of your schema supporting items of your rs array being a document themselves.

Hope this helps

Community
  • 1
  • 1
fgakk
  • 1,289
  • 1
  • 15
  • 26
  • Wow, not possible. I voted for the Jira. The approaches suggested in the thread look like can consume a lot of memory... I mean it has to load the whole collection in memory. Also doing this asynchrounously... waiting that each update is finished... pffft. I might restructure my documents like you say or just skip the planned functionality for now. – User Oct 01 '13 at 20:28
  • With so many votes and requests i think they will provide a clean solution to this. Well hopefully... – fgakk Oct 01 '13 at 20:59