How to aggregate 2 sharded collections

i have 2 sharded collections sender and receiver like this:
rule:
send type equal 10 must be receivered 12 or 12 and 13
send type equal 20 must be receivered 22 or 24
send type equal 23 must be receivered 24

db.sender.insert(
   [
     { _id: 20, senderCode: "012321", senderType: "10", message: "send10" },
     { _id: 21, senderCode: "012331", senderType: "20", message: "send20" },
     { _id: 22, senderCode: "012341", senderType: "23", , message: "send23" }
   ]
)

and

db.receive.insert(
   [
     { _id: 20, receiverCode: "09202", referenceCode:"012321", receiveType: 12, message: "recei10v1" },
     { _id: 21, receiverCode: "09203", referenceCode:"012321", receiveType: 13, message: "recei10v2" },
     { _id: 22, receiverCode: "09201", referenceCode:"012341", receiveType: 22 , message:"recei20v1"}
)

i wanna find senderCode which is missing receiver message
i try to use $lookup but mongo do not allow lookup from sharded collection.
Can another way can resolve this problem ?
Please help

sorry. value number 3 in receive collection must be like this

Hi @le_an ,

Version 5.1 which is for production only on Atlas for now, will allow you to lookup 2 sharded collections.

Otherwise, the only way is to do in application or script logic when you query one side and perform a lookup on a second query.

Thanks
Pavel

1 Like