【发布时间】:2017-07-08 15:37:58
【问题描述】:
我有一个电影集合,并且该电影集合有一个嵌入的评论文档数组。我想选择所有 status=1 的评论
{
reviews: [
{
status: 0,
text: 'hello'
}, {
status: 1,
text: 'hi'
}
}, {
... etc ...
【问题讨论】:
我有一个电影集合,并且该电影集合有一个嵌入的评论文档数组。我想选择所有 status=1 的评论
{
reviews: [
{
status: 0,
text: 'hello'
}, {
status: 1,
text: 'hi'
}
}, {
... etc ...
【问题讨论】:
同样的问题有答案:Filtering embedded documents in MongoDB
在当前稳定版本的 mongodb 中,仍然无法进行嵌入式文档过滤。
在 2.1.0 中有聚合。您可以使用unwind 和match 过滤评论
不过我自己没试过。
【讨论】: