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

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

It is not possible to query using lookup in two different db’s.
$lookup in mongodb supports Performs a left outer join to an unsharded collection in the same database.

{
   $lookup:
     {
       from: <collection to join>,
       localField: <field from the input documents>,
       foreignField: <field from the documents of the "from" collection>,
       as: <output array field>
     }
}

We can use getSibling("dbname") to query another db from one db

db.getSiblingDB('test').foo.find()

Reference – MongoDB cross database query

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)