Image
As you all can see the in the image the postImage is showing Array(0), I have used the following code.
dbs.collection('posts').aggregate([
{
$lookup:{
from: "images",
localField: "_id",
foreignField: "object_id",
as: "postImage"
}
},
]).toArray((err, res) => {
if(err) throw err;
doc.send(JSON.stringify(res));
dbs.close();
})
Image of databse:-
post collection
Here posts collections _id matches to the object_id with the images collection. I want to fetch both the data. what should I do?
Thank You in advance.
I think so it will work after modifying code to this.
{
"$project": {
"_id": {
"$toString": "$_id"
}
}
},
before using $lookup