是否可以在 Mongodb 中的两个数据库之间进行 $lookup 聚合?

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

我正在尝试做这样的事情:

use user; 

db.user.aggregate([
    {
      $lookup:
        {
          from: "organization.organization",
          localField: "organizationId",
          foreignField: "uuid",
          as: "user_org"
        }
   }
])

userorganization 在两个不同的数据库中。

如果这不可能,有什么替代方案?

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

无法在两个不同的数据库中使用查找进行查询。 mongodb 中的 $lookup 支持对同一数据库中的未分片集合执行左外连接。

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

我们可以使用getSibling("dbname")从一个数据库查询另一个数据库

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

参考 - MongoDB cross database query

是的,请阅读以下 mongodb 文档:

在 Atlas Data Lake 中,$lookup 可用于执行来自不同数据库的集合的连接。

https://docs.mongodb.com/datalake/reference/pipeline/lookup-stage