0

I have a document like given below to store categories.

  {
            "_id": "59c7db58279a6b0004d0872d",
            "level": 3,
            "shop_id": "59c7db58279a6b0004d0872c",
            "category": [
                {
                    "level1": {
                        "name": "kids",
                        "endpoint": "Dtoblyw9qxlwN3Pg2MY0OopP8.webp"
                    },
                    "level2": {
                        "name": "Girls",
                        "endpoint": "Dtoblyw9qxlwN3Pg2MY0OopP8.webp"
                    },
                    "level3": [
                        {
                            "name": "Flats and Bellies",
                            "endpoint": "veWJ2lgwa7kU9m3IBtraT7i8m.webp"
                        },
                        {
                            "name": "Sports",
                            "endpoint": "7NZlzQczthKDMMRpbz5eqp9yV.webp"
                        }
                    ]
                }
            ]
        }

I want to update or set a specific name in a sub document of level3. All name in level3 are unique. And i know particular name i need to update.

Update: Level1 and level2 are object but level3 is a array of object.I just need to update any particular object in level3 array.

  • do u also know which `level` to update? Can `level` be both object and array? – sidgate Sep 27 '17 at 10:40
  • 2
    you have nested array. Feature to updated nested array is fixed in next mongo release https://jira.mongodb.org/browse/SERVER-831. Till then you have to manually iterate and save each document – sidgate Sep 27 '17 at 10:45
  • @sidgate I update my question. pls read it once. – Bhupendra Singh Chauhan Sep 27 '17 at 11:33
  • you can update this document in single query in mongodb 3.4( array filters) for less than 3.4 you need to use two queries first find that document make changes and then update – Shubham Sep 28 '17 at 08:15
  • Possible duplicate of [Updating a Nested Array with MongoDB](https://stackoverflow.com/questions/23577123/updating-a-nested-array-with-mongodb) – s7vr Sep 28 '17 at 15:38

0 Answers0