2

次のように、ネストされたオブジェクトを含む Word スキーマがあります。「elementary_one_reading」で値が xxx の単語を検索したい場合は、次のように簡単に実行できます。db.words.find({"apperance.elementary_one_reading": xxx})

ただし、キーの変数を渡したいと仮定して、マングースでこれを行う方法を考えていました。特に、以下のような方法があればいいのにと思っていたのですが、うまくいきません。

function(key, value) {
    Word.find({"appearance." + key: value}, function(err, results) {
    }

}


{ "word" : "岁", "_id" : ObjectId("1"), "appearance" : { "elementary_one_reading" : [ 1 ] }}
{ "word" : "女", "_id" : ObjectId("2"), "appearance" : { "elementary_one_reading" : [ 1 ] }}
{ "word" : "我", "_id" : ObjectId("3"), "appearance" : { "elementary_two_reading" : [ 1, 8 ] }}
{ "word" : "你", "_id" : ObjectId("4"), "appearance" : { "elementary_two_reading" : [ 1, 2 ] }}
4

1 に答える 1