A query gave me the required result in MongoDB while it's returning an empty array in mongoose
db.users.aggregate([
{$match:{_id:ObjectId("5d5a8b83352b262670a4d47b")}},
{
$lookup:
{
from: "userclaims",
localField: "_id",
foreignField: "userId",
as: "claims"
}},{
$unwind:"$claims"
}
])
this query, when executed in mongodb terminal, yielded the right result
User.aggregate([
{$match:{_id:mongoose.Types.ObjectId("5d5a8b83352b262670a4d47b")}},
{
$lookup:{
from:"UserClaim",
localField:"_id",
foreignField:"userId",
as:"claims"
}
},{
$unwind:"$claims"
}
])
.exec().then((claims)=>{
console.log(claims)
}).catch((err)=>{
console.log(err);
})
this is the code that I've written in mongoose which is logging []
.