I was playing with Mongodb and wanted a query that use lookup and $push or $addToSet
See this https://mongoplayground.net/p/4hSPKW_bCdM
How can i make this query correct. do we need loop over here ?
Should return
{
"response": [
{
"_id": "5fcdcc14da26c80a6de06754",
"first_name": "James",
"last_name": "Hales",
"username": "jim",
"timestamp": 1607322644202,
"userData": [
{
"_id": "6011021851781d3d9841e09d",
"user_id": "5fcdcc14da26c80a6de06754",
"photo": [
{
"_id": "6011021851781d3d9841e09e",
"url": "http://localhost:3000/files/ou93r0cfjde0cat.jpg",
"width": 250,
"height": 500,
"preview": "skjdfbsdjvns;svnsdvisdvnvsdjvnsdivsdkvsdivsdjvnsdjvsdvsdvgjsvnsvhi"
}
],
"status": "Active",
"timestamp": 1611727384083,
"expire_at": "2021-01-27T06:03:04.083Z"
},
{
"_id": "6011021851781d3d9841e09d",
"user_id": "5fcdcc14da26c80a6de06754",
"photo": [
{
"_id": "6011021851781d3d9841e09e",
"url": "http://localhost:3000/files/ou93r0cfjee0bat.jpg",
"width": 250,
"height": 500,
"preview": "skjdfbsdjvns;svnsdvisdvnvsdjvnsdivsdkvsdivsdjvnsdjvsdvsdvgjsvnsvhi"
}
],
"status": "Active",
"timestamp": 1611727384083,
"expire_at": "2021-01-27T06:03:04.083Z"
}
]
}
]
}
Thank in advance
question from:
https://stackoverflow.com/questions/65915319/how-to-use-lookup-along-with-push-in-mongodb 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…