Been struggling with this for a while can't work out why I am always getting an empty array for my loop up data.
I have data in my 'users' collection
{
storeid: 1,
name: 'joe bloggs'
}
I have a stores collection with the following data in
{
_id: ObjectId(1),
storeName: 'Store name'
}
I want to pull the storename that each user is part of when getting all users. I have a query like the below to do this:
User.aggregate([
{
$lookup: {
from: "store",
localField: "storeid",
foreignField: "_id",
as: "storeDetail"
}
}
])
.then(users => {
res.send(users);
}).catch(err => {
//error
});
However what I get here is 'storeDetail' always returning blank. Not too sure what I am doing wrong, I have checked that my collection names are correct as per db.getCollectionNames() from the mongo shell.
Thanks,