var footballerIdToPassive = "qqqqq";
var footballerlevelToPassive = ["3052002","3052003"];
db.goals.find({ "footballer": footballerIdToPassive, "footballerlevel": { $in: [footballerlevelToPassive]}}))
因为它只带来了目标db shell,当我运行计数时,count是1
{ "footballer": "qqqqq", "footballerlevel": "3052002" }
也适用于
var footballerlevelToPassive = "3052002";
这个,它有效。但我无法做到多重。我可以做这项工作吗?
我需要使用每个,我需要更新每个
答案 0 :(得分:3)
footballerlevelToPassive
已经是一个数组,您无需再次在查询中将其包装在另一个数组中,只需将其$in
直接引用为
var footballerIdToPassive = "qqqqq";
var footballerlevelToPassive = ["3052002","3052003"];
db.goals.find({
"footballer": footballerIdToPassive,
"footballerlevel": { "$in": footballerlevelToPassive }
})
等同于查询
db.goals.find({
"footballer": footballerIdToPassive,
"$or": [
{ "footballerlevel": "3052002" },
{ "footballerlevel": "3052003" }
]
})
快速演示