I have model like this
{
"array1": [
{
"_id": "12",
"array2": [
{
"_id": "123",
"answeredBy": []
}
]
}
]
}
If I have id in array1, push the document into array2 or create new document in array1.
Eg:
If I give have new object
{
"array1": [
{
"_id": "123",
"array2": [
{
"_id": "123",
"answeredBy": [],
},
{
"_id": "456",
"answeredBy": []
}
]
}
]
}
else if give _id of array1 as other than 123 i.e., non existing i.e., 657
The result should be:
{
"array1": [
{
"_id": "123",
"array2": [
{
"_id": "123",
"answeredBy": [],
}
]
},
{
"_id": "657",
"array2": [
{
"_id": "456",
"answeredBy": [],
}
]
}
]
}
How can I achieve this?