0

I've asked this before, but people just want to label this a duplicate instead of answering it.

Looking for a simple answer here. Can the below be done or not?

I have a huge schema that I inherited. It has an array of objects and I am targeting an array of objects nested within that. cssClass is what I'm trying to update. Here is the schema

board: {
  "lists": [
    { "id": 12,     
      "cards": [
        { "id": 123,
          "cssClass": "default"
        },
        { "id": 124,
          "cssClass": "default"
        }
      ]
    }
  ]
}
s.Lawrenz
  • 302
  • 3
  • 17
  • Is "board` your document or a field on a document? Also, what exactly do you want to update? Give us a "before" and "after" version and we might be able to help. Also, please strip out the irrelevant part at the bottom - the `{id:13,cards:[]}` stuff. And, most importantly, which MongoDB version are you using? And lastly, the referenced answer in your question that got marked as duplicate is a really good one - try to understand that, especially in your case the part about MongoDB 3.6: https://stackoverflow.com/questions/23577123/updating-a-nested-array-with-mongodb – dnickless Nov 14 '17 at 19:56
  • I'm needing to update the cssClass in the cards nested array. I'm using Mongo 3.4.9. – s.Lawrenz Nov 14 '17 at 20:25
  • In MongoDB < 3.5.2 (preview release, not really production level), this cannot be done one the server side. There are, however, client-side solutions to this involving loops as described in the (not accepted) answers here: https://stackoverflow.com/questions/19603542/mongodb-update-data-in-nested-field – dnickless Nov 14 '17 at 21:15
  • Well... with versions < 3.6 there is no way that doesn't include a lot of manual work. There are ways, but none of them generic. The next upcoming stable release will be 3.6 so you'd have to upgrade. – Alex P. Nov 14 '17 at 21:33

0 Answers0