本文介绍了是否可以在 Mongodb 中的两个数据库之间进行 $lookup 聚合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试做这样的事情:
I'm trying to do something like this:
use user; db.user.aggregate([ { $lookup: { from: "organizationanization", localField: "organizationId", foreignField: "uuid", as: "user_org" } } ])user 和 organization 在两个不同的数据库中.
user and organization are in two different databases.
如果这是不可能的,有什么替代方法?
推荐答案是否可以在两个数据库之间进行 $lookup 聚合MongoDB?
Is it possible to do a $lookup aggregation between two databases in Mongodb?
不可能在两个不同的数据库中使用查找进行查询.mongodb 中的 $lookup 支持对未分片集合执行左外连接在同一个数据库中.
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> } }我们可以使用 getSibling("dbname") 从一个数据库查询另一个数据库
We can use getSibling("dbname") to query another db from one db
db.getSiblingDB('test').foo.find()参考 - MongoDB 跨数据库查询
更多推荐
是否可以在 Mongodb 中的两个数据库之间进行 $lookup 聚合?
发布评论