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

编程入门 行业动态 更新时间:2024-10-25 16:27:30
本文介绍了是否可以在 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 聚合?

本文发布于:2023-11-22 13:02:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1617516.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   数据库   Mongodb   lookup

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!