2
다음과 같이 중첩 된 개체가 포함 된 Word 스키마가 있습니다. 나는 가치 XXX로 "elementary_one_reading"에서 단어를 검색하고 싶다면, 난 그저 내가 키에 대한 변수를 전달하고 싶었 가정, 내가 몽구스에서 이런 짓을 했을까 궁금했다, 그러나 db.words.find({"apperance.elementary_one_reading": xxx})
mongodb/mongoose에서 키로 검색
을 할 수 있습니다. 특히 나는 아래와 같은 것을 할 수있는 방법이 있기를 희망했지만 작동하지 않습니다.
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 ] }}