Hello everyone, I started using mongodb after a long time, but I could not write the code to perform the following operation.
At first, I tried this code but didn’t get the desired result and couldn’t continue due to the example shown as an empty array.
{$lookup: {
from: 'suspects',
localField: 'suspects.id',
foreignField: '_id',
as: 'example1'
}}
lawyers document
_id
fullName
phoneNumber
suspects document
_id
fullName
phoneNumber
case document
_id
crimeNumber
eventDate
suspects: [
{
id // _id value in the suspects document
note
+++ populating data from suspects document
lawyer: {
id // _id value in the lawyers document
note
+++ populating data from lawyers document
}
}
...
...
]