0

I have collection with a document structure that looks like this:

{
    id : 1,
    name : "height",
    datasets : [
        {
            version : 1.1,
            data : [{x: 0, y: 1}, {x: 1, y: 2}]
        }
    ]
}

I want to push another object {x: 2, y: 3} to the 'data' array of an object in 'datasets' where 'version' is 1.1.

I've tried multiple combinations but I don't seem to get the right one.

How can this be achieved?

Thanks

guygrinberger
  • 327
  • 2
  • 14
  • 1
    You can update the nested array using the [filtered positional operator](https://docs.mongodb.com/manual/reference/operator/update/positional-filtered/#update-nested-arrays-in-conjunction-with). – prasad_ Apr 16 '20 at 12:12
  • 1
    Here is a post with an answer about pushing a document into a nested array: [How to add a json in a nested array of a mongodb document using Spring?](https://stackoverflow.com/questions/60701824/how-to-add-a-json-in-a-nested-array-of-a-mongodb-document-using-spring). The post shows three levels of nesting; but, you can use the same technique and apply for your case. – prasad_ Apr 16 '20 at 12:19
  • @whoami yes it did. – guygrinberger Apr 18 '20 at 09:02

0 Answers0