1

これは私のコレクション構造です:

コール{

id:...,

..,

fieldA:{

   fieldA1:[

       {

           ...

       }

   ],

   ...,

   fieldA2:[

       {

           text: "ciao",

       },

       {

           text: "hello",

       },

       ...  

   ] 

} 

...

}

たとえば、text="ciao" を使用してドキュメントを検索したい場合は、次を使用します: Db.coll.find({fieldA: { fieldA2: {$elementMatch:{ text:”ciao”} } } }) しかし、結果は何も... この操作を行うにはどうすればよいですか? ありがとうございます!

4

1 に答える 1

1

埋め込まれたドキュメントを参照するには、ドット表記を使用する必要があります。

db.coll.find({'fieldA.fieldA2': { $elemMatch:{ text:"ciao"} }})

また、演算子は$elemMatch$elementMatch ではなく であることに注意してください。

于 2012-12-12T20:43:19.930 に答える