mongodb 中做 join 的方法

在MongoDB中,官方并不支持JOIN查询。针对这种情况,可以利用MongoDB的数据计算工具,如SPL,来实现类似的功能。例如,查询employee.state为California的sales orders,需要分别从employee和seller文档中获取数据,然后通过SPL进行处理,得到满足条件的结果。这种方法虽然比直接JOIN查询复杂,但能完成所需的数据整合。
摘要由CSDN通过智能技术生成

【问题】

Imagine you have a collection for posts, and each of these posts has the attribute userid: ObjectId( ), where ObjectID is referencing a document in the Users collection.

How would you go about retrieving the user information (in this case, the user document might contain a username, email, full name, etc) as part of a query on the Posts collection?

【回答】

用 Mongodb 是不支持 join 查询的, 要多次查询很不方便。可以考虑配合 mongodb 使用的本身有计算能力的工具,比如使用 SPL。举例说明:

通过 employee 文档和 seller 文档查询 employee.state 为 California 的 sales orders。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值