Hello and sorry for the title, it is quite hard to explain with words.
I have data with multiple levels in the mongo collection.
I am trying to insert a value inside the maps array which is already inside favorite_lists array of objects. Below is the user collection schema:
{
"_id" : ObjectId("60f3fdae2367163726c6716b"),
"username" : "Johnny65",
"first_name" : "Thaddeus",
"last_name" : "Lueilwitz",
"email" : "[email protected]",
"mobile" : "834XXXX",
"profile_photo" : "http://placeimg.com/640/480",
"login_type" : 2,
"maps_created" : ISODate("2020-04-08T20:00:28.453Z"),
"created_date" : ISODate("2021-06-24T16:19:07.010Z"),
"favorite_lists" : [
{
"maps" : [ ],
"name" : "name 1",
"created_date" : ISODate("2021-07-20T13:27:56.050Z")
},
{
"maps" : [ ],
"name" : "name 2",
"created_date" : ISODate("2021-07-20T13:31:21.985Z")
},
{
"maps" : [ ],
"name" : "name 3",
"created_date" : ISODate("2021-07-20T13:35:32.959Z")
}
]
}
I want to insert value inside maps array where favorite_lists.name = "name 2"
Expected Result
{
"_id" : ObjectId("60f3fdae2367163726c6716b"),
"username" : "Johnny65",
"first_name" : "Thaddeus",
"last_name" : "Lueilwitz",
"email" : "[email protected]",
"mobile" : "834XXXX",
"profile_photo" : "http://placeimg.com/640/480",
"login_type" : 2,
"maps_created" : ISODate("2020-04-08T20:00:28.453Z"),
"created_date" : ISODate("2021-06-24T16:19:07.010Z"),
"favorite_lists" : [
{
"maps" : [ ],
"name" : "name 1",
"created_date" : ISODate("2021-07-20T13:27:56.050Z")
},
{
"maps" : ["value 1", "value 2" ],
"name" : "name 2",
"created_date" : ISODate("2021-07-20T13:31:21.985Z")
},
{
"maps" : [ ],
"name" : "name 3",
"created_date" : ISODate("2021-07-20T13:35:32.959Z")
}
]
}