I have two documents with a DBRef relation between those documents.
Task document:
{
"_id": 77,
"title": "Test title",
"status": "in-progress",
"reporter": {
"$ref": "User",
"$id": ObjectId("5daf022549a36e319879f357"),
"$db": "test"
},
"priority": "high",
"project": {
"$ref": "Project",
"$id": 30,
"$db": "gsc"
}
}
User Document:
{
"_id": ObjectId("5daf022549a36e319879f357"),
"username": "user1",
"email": "test@gmail.com",
"is_active": true,
"firstName": "user-1"
}
I tried below query but I didn't get proper result
db.Task.findOne($lookup:
{
from: User,
localField: reporter,
foreignField: reporter._id,
as: User_Task
}
)
How to perform the JOIN? Also, want to both document all data? I want data from Task Document and suggest how to join with project field.
Need this kind of result:
{
"_id" : 77,
"title" : "Test title",
"status" : "in-progress"
"reporter" :
{
"_id" : ObjectId("5daf022549a36e319879f357"),
"username" : "user1",
"email" : "test@gmail.com"
"is_active" : true,
"firstName" : "user-1"
},
"priority" : "high",
"project" : {}
}