【发布时间】:2019-01-07 16:11:06
【问题描述】:
假设我有一组用户
_id: ...
name: 'the name'
还有一组cmets
_id: ...
comment: 'the comment'
poster: user_id
然后使用单个查询从用户列表中获取最后一个 cmets?
【问题讨论】:
-
你能发布样本集吗
标签: mongodb collections
假设我有一组用户
_id: ...
name: 'the name'
还有一组cmets
_id: ...
comment: 'the comment'
poster: user_id
然后使用单个查询从用户列表中获取最后一个 cmets?
【问题讨论】:
标签: mongodb collections
在单个查询中实现它的唯一方法是使用 $lookup 阶段运行聚合管道 https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/
【讨论】: