I have two collections.
Customers:
{
"_id" : ObjectId("584aac38686860d502929b8b"),
"name" : "user",
"email" : "[email protected]"
}
Posts:
{
"_id" : ObjectId("584aaca6686860d502929b8d"),
"title" : "Post",
"description":"description",
"user_id" : "584aac38686860d502929b8b"
}
I want to join this collection based on the user_id (from posts collection) - _id ( in customers collection).
I tried the below query:
dbo.collection('customers').aggregate([
{
$lookup:
{
from: 'posts',
localField: 'user_id',
foreignField: '_id',
as: 'posts'
}
}
])
but it's not working.
The output I am getting:
{
"_id": "584aac38686860d502929b8b",
"name": "user",
"email": "[email protected]",
"posts": []
}