2016-06-28 3 views
0

私は次のような構造で文書を含むモンゴデータベースと流星のアプリケーションを持っている:値が入れ子になっているMiniMongoからドキュメントを取得するには?

_id: "1234567890", 
blocks: [{ 
    type: "block",    
    block_id: "foobar", 
    items: [ 
     { 
      type: "sub", 
      sub_id: "111", 
      items: [ 
       { 
        type: "question", 
        question_id: "aaa" 
       }, 
       { 
        type: "question", 
        question_id: "bbb" 
       } 
      ] 
     }, 
     { 
      type: "question", 
      question_id: "aaa" 
     } 
    ] 
}] 

私は「aaa」のquestion_idですべての質問を見つけることができるようにしたいです。これまでのところ私は、これらのクエリを試してみましたが、どんな結果を返すのに苦労しています:

questions = MyColl.find({ 
    $or: [{ 
     blocks: { 
      items: { 
       $elemMatch: {question_id: 'aaa'} 
      } 
     } 
    },{ 
     blocks: { 
      items: { 
       type: "sub", 
       items: { 
        question_id: 'aaa' 
       } 
      } 
     } 
    }] 
}).count(); 

任意のアイデア?

答えて

0

これは私がそれをmananged方法です:

questions = MyColl.find({ 
      $or: [{ 
       'blocks.items': { 
        $elemMatch: {question_id: 'aaa'} 
       } 
      },{ 
       'blocks.items.items': { 
        $elemMatch: {question_id: 'aaa'} 
       } 
      }] 
     }).count(); 
関連する問題