0

I've a mongo collection which contains documents with a set of complex (embedded) arrays with some fields. The document structure looks as follows:

{
    "_id" : "123",
    "rootTree" : [ 
        {
            "levels" : [ 
                {
                    "id" : "01",
                    "name":"dummy name",
                    "address" : "smth street 1",
                    "city" : "somecity",
                    "country" : "somecounrty",
                    "remark" : "test1"
                }, 
                {
                    "id" : "02",
                    "name":"dummy2 name",
                    "address" : "another street 10",
                    "city" : "anothercity",
                    "country" : "anothercounrty",
                    "remark" : "test5"
                }
            ]
        }, 
        {
            "levels" : [ 
                {
                    "id" : "125",
                    "name":"dummy85 name",
                    "address" : "street 987",
                    "city" : "city52",
                    "country" : "counrty52",
                    "remark" : "test1"
                }
            ]
        }
        // etc.
    ]
}

I need to somehow iterate over the documents (rootTree and levels) and set another value to all remark fields whose values are test1. I tried with some scripts with find() and aggregate() but can't get my desired results, this is because I'm new in MongoDB world. So, any help would be appreciated.

MongoDB Version 3.4 and 3.6

bofanda
  • 10,386
  • 8
  • 34
  • 57

0 Answers0