0

我有一个像这样的数据结构:

Post
{
'id': $_id,
'user' : ['first_name' : 'Joe', 'last_name' : 'Devon' ],
'text' : 'blah',
'comment' : 
  ['first' : 'Joe', 'last' : 'Devon', 'comment' : 'hello'],
  ['first' : 'John', 'last' : 'Smith', 'comment' : 'bye', 'hidden' : true],
  ['first' : 'Joe', 'last' : 'Devon', 'comment' : 'world']
},
{
'id': $_id,
'user' : ['first_name' : 'Joe', 'last_name' : 'Shmoe' ],
'text' : 'meh',
'comment' : 
  ['first' : 'Joe', 'last' : 'Devon', 'comment' : 'sup'],
},
{
'id': $_id,
'user' : ['first_name' : 'Mr.', 'last_name' : 'Smith' ],
'text' : 'bah',
'comment' : 
  ['first' : 'Joe', 'last' : 'Devon', 'comment' : 'sup mon'],
}

我正在尝试运行一个查询,该查询将返回除具有“隐藏”的评论之外的所有内容:true。

尝试了所有不起作用的方法。寻找一个可行的命令。请帮忙 :)

4

1 回答 1

2

目前这对于 mongodb 是不可能的,您必须在客户端过滤评论。

过滤机制仅用于匹配或不匹配整个文档,然后检索其字段的子集,但不幸的是,您无法指定返回哪些字段的标准。

如果你有一个评论集合,你可以过滤掉那些有hidden: true.

于 2011-12-23T16:42:47.333 回答