0

i want to update the value. The gap should be located with his id and the id from the pocket. I tried with the updateOne() function but i could not find the path vor the gap. Maybe you can help me.

There will be more objects in the pockets and gaps arrays.

{
    "_id":"5a4f535f4dc4b200d43cf333",
    "id":"A07","name":"name",
    "capacity":"230",
    "free":"230",
    "open":false,
    "location":
        {
            "longitude":51.02274,
            "latitude":7.5612
    },
    "pockets":
        [
            {
                "id":"A",
                "description":"Parktasche",
                "capacity":12,
                "free":11,
                "gaps":
                    [
                        {
                            "id":"7",
                            "value":true,      <-- should be updating
                            "deployee":false,
                            "disabled":false,
                            "guest":false,
                            "pid":"A"
                        }
                    ]
            }
        ]
    }
sukramx
  • 13
  • 3
  • `pockets[0].gaps[0].value` – connexo Jan 20 '18 at 23:26
  • Sry, i forgot something. There will be more pocket objects and gap objects in this arrays. I want to locate the right pocket with the gap Id and the pocket id. – sukramx Jan 20 '18 at 23:30
  • Possible duplicate of [Updating a Nested Array with MongoDB](https://stackoverflow.com/questions/23577123/updating-a-nested-array-with-mongodb) – s7vr Jan 20 '18 at 23:37

1 Answers1

0

If I remember correctly, you need something like pockets.$.gaps.$.value

https://docs.mongodb.com/manual/reference/operator/update/positional/#update-documents-in-an-array

One More Light
  • 175
  • 1
  • 9