Hmm…I’m not sure what you mean. I can run this in a single query:
db.b.aggregate([{
$lookup: {
from: 'a',
localField: 'accountId',
foreignField: 'accountId',
as: 'infoFromA'
}
}, {
$lookup: {
from: 'c',
localField: 'trx',
foreignField: 'trx',
as: 'infoFromC'
}
}])
Below is the output:
{ "_id" : ObjectId("5f5a12bf931c05e9b75e0f87"), "accountId" : "1", "hi" : "there", "trx" : "one", "infoFromA" : [ { "_id" : ObjectId("5f5a12a0931c05e9b75e0f85"), "accountId" : "1", "something" : "else" } ], "infoFromC" : [ { "_id" : ObjectId("5f5a12f1931c05e9b75e0f89"), "trx" : "one", "waz" : "up" } ] }
{ "_id" : ObjectId("5f5a12c8931c05e9b75e0f88"), "accountId" : "3", "hello" : "again", "trx" : "one", "infoFromA" : [ ], "infoFromC" : [ { "_id" : ObjectId("5f5a12f1931c05e9b75e0f89"), "trx" : "one", "waz" : "up" } ] }
If that is not what you mean, please provide sample documents for each collection as well as the output you are looking for.