0

Say, I have a document structure

[ {
  "name" : "in",
  "states" : [ {"name" : "up", 
                "cities" : [ {"name" : "dp", "places" : [ {"name" : "pvr"}, {"name" : "lpu"} ] }, 
                            {"name" : "mo", "places" : [ {"name" : "pvr"}, {"name" : "lpu"} ] } ]}, 
               {"name" : "tn", 
               "cities" : [ {"name" : "ab", "places" : [ {"name" : "pvr"}, {"name" : "lpu"} ] }, 
                            {"name" : "cd", "places" : [ {"name" : "pvr"}, {"name" : "lpu"} ] } ]} 
             ]
  },
  {
  "name" : "ik",
  "states" : [ {"name" : "up", 
                "cities" : [ {"name" : "dp", "places" : [ {"name" : "pvr"}, {"name" : "ont"} ] }, 
                            {"name" : "lo", "places" : [ {"name" : "zcv"}, {"name" : "bft"} ] } ]}, 
               {"name" : "kl", 
               "cities" : [ {"name" : "hp", "places" : [ {"name" : "bgh"}, {"name" : "vhi"} ] }, 
                            {"name" : "mp", "places" : [ {"name" : "hup"}, {"name" : "plm"} ] } ]} 
             ]
} ]

I would like to change the "{"name" : "pvr"}" to "{"name" : "cvr"}" of "places" where ("name":"ik" and "states.name":"up" and "cities.name":"dp"). How to check for all three conditions and update?

1 Answer 1

1

Since the position of array element you want to update is unknown, you will need to fetch the matching states and cities, iterate over places and the set the new value in your application code. Alternatively, you can model your data differently if this kind of update is done frequently so you do not have so many levels deep of array elements.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.