I am currently working with mongoDB.
I have a collection called Users with the following document:
{
_id: "5d93f338e602a10a38ad3588",
userID: "1",
email: "test@test.com",
password: "password",
firstName: "Tom",
lastName: "Bombadil"
}
I also have a collection called Posts. with a document:
{
_id: "5d93fddce602a10a38ad358a",
postID: "1",
userID: "1",
postContent: "hello world"
}
I am able to 'join' these two with the following $lookup from Users:
{
from: 'Posts',
localField: 'userID',
foreignField: 'useriD',
as: 'usersPosts'
}
How can I write a Query to get the "postContent" of said Post? Something along the lines of:
db.Users.find($lookup : {
from: 'Posts',
localField: 'userID',
foreignField: 'useriD',
as: 'usersPosts'
} : userPosts[0]