I am new to mongoDB. I am having some trouble in updating the records in mongoDB collection.
How to add elements into array likes
into the embedded record
I have a embedded collection like:
{
"_id": "iL9hL2hLauoSimtkM",
"title": "Some Topic",
"followers": [
"userID1",
"userID2",
"userID3"
],
"comments": [
{
"comment": "Yes Should be....",
"userId": "a3123",
"likes": [
"userID1",
"userID2"
]
},
{
"comment": "No Should not be....",
"userId": "ahh21",
"likes": [
"userID1",
"userID2",
"userID3"
]
}
]
}
I want to update the record as
{
"_id": "iL9hL2hLauoSimtkM",
"title": "Some Topic",
"followers": [
"userID1",
"userID2",
"userID3"
],
"comments": [
{
"comment": "Yes Should be....",
"userId": "a3123",
"likes": [
"userID1",
"userID2",
"userID3" // How to write query to add this element.
]
},
{
"comment": "No Should not be....",
"userId": "ahh21",
"likes": [
"userID1",
"userID2",
"userID3"
]
}
]
}
Please provide the query to add the element shown in comment.
Thank you.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…