我目前有一个 Question 对象,但不确定如何查询它?
{ "title" : "Do you eat fast food?"
"answers" : [
{
"_id" : "506b422ff42c95000e00000d",
"title" : "Yes",
"trait_score_modifiers" : {
"hungry" : 1
}
},
{
"_id" : "506b422ff42c95000e00000e",
"title" : "No",
"trait_score_modifiers" : {
"not-hungry" : -1
}
}]
}
我正在尝试查找查询 trait_score_modifieres 的问题(有时存在,有时不存在)
我有以下内容,但它不是动态的:
db.questions.find({"answers.trait_score_modifiers.not-hungry":{$exists: true}})
我怎么能做这样的事情?
db.questions.find({"answers.trait_score_modifiers.{}.size":{$gt: 0}})