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'],
}

'hidden':trueのコメントを除くすべてを返すクエリを実行しようとしています。

動作しないすべてを試しました。動作する1つのコマンドを探しています。助けてください :)

4

1 に答える 1

2

これは現在mongodbで行うことは不可能であり、クライアント側でコメントをフィルタリングする必要があります。

フィルタリングメカニズムは、ドキュメント全体に一致するか一致しない場合にのみ機能し、フィールドのサブセットを取得しますが、残念ながら、どちらを返すかについての基準を指定することはできません。

コメントのコレクションがある場合は、を含むものを除外できますhidden: true

于 2011-12-23T16:42:47.333 に答える