0

db_contacts collection_contact

{
"_id" : ObjectId("5ac5d63cf0b6c601a8978b56"),
"contact_type" : "Individual",
"name" : "MyShipper",

} ...

db_shipments collection_fclshipments

"shipper_info" : {
    "shipper" : ObjectId("5ac5d63cf0b6c601a8978b56"),
    "same_as_billing_address" : true
} ...

I want to join two collections from two different databases. I have tried $lookup method. But it is not possible. And also tried db.getSibling / db.getSiblingDB. Please suggest any proper way to handle this situation. Thank you.

  • As specified in the [`$lookup`](https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/) documentation *"... Performs a left outer join to an unsharded collection in the **same** database"*. Therefore if it's not in the same database, the "server" cannot do the "join". Other methods listed are not really "server joins", but emulations done by specifically issuing another query to the server, based on results obtained from a previous query. Use one of those or move your collections into the **same** database. – Neil Lunn Apr 20 '18 at 02:53
  • @NeilLunn Thank you. If possible! Can you please describe your solution with small example? – Naga Prasanth Apr 20 '18 at 02:57
  • Other people already did. Big box hanging over the top of your question. Read it. – Neil Lunn Apr 20 '18 at 03:00

0 Answers0