$lookup across 2 databases

Is it possible to do a $lookup aggregation between two databases in Mongodb ?

I try this documentation, but the results is empty array

It should work as documented. The empty result is probably cause by something else being wrong, like wrong field names, wrong values, wrong operators. It would hel if you share your pipeline.

This is my pipeline

      $lookup: {
        localField: '_id',
        from: 'view_main_dealer_package_products',
        foreignField: 'product_id',
        as: 'package_product',

Welcome to the community @RindangRamadhan!

As at MongoDB 4.4, $lookup only supports looking up from collections in the same database. Per the $lookup documentation for the from field:

Specifies the collection in the same database to perform the join with. The from collection cannot be sharded.

There is a relevant feature request you can upvote & watch: SERVER-34935: Support cross-database lookup.


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.