My documents in the orders collection has _client
key, which is an ObjectId references to another entity in another collection.
The collection could be organization and could be users - I mean - it's variable collection.
I want to tell Mongo to lookup if the _client id is found in both collections.
{
$lookup: {
from: "users", // could be "organizations"
let: { "client": "$_client" }, // could be "_organization"
pipeline: [
{ $match: { $expr: { $eq: ["$_id", "$$client"] }}},
],
as: "client"
}
},
{
$unwind: "$client"
},
I have tried to just set up two look ups, once for _client and one for _organization however when there one of them is missing, I just got no results at all.