Reputation: 737
var footballerIdToPassive = "qqqqq";
var footballerlevelToPassive = ["3052002","3052003"];
db.goals.find({ "footballer": footballerIdToPassive, "footballerlevel": { $in: [footballerlevelToPassive]}}))
for that it brings nothing but in goals db shell, when i run count of this, count is 1
{ "footballer": "qqqqq", "footballerlevel": "3052002" }
also for
var footballerlevelToPassive = "3052002";
this, it works. but i cant do for multiple. HOw can i do this work?
i need to use each , i need to update each one
Upvotes: 1
Views: 37
Reputation: 103445
footballerlevelToPassive
is already an array, there's no need to wrap it in another array again in your query, just reference it directly with $in
as
var footballerIdToPassive = "qqqqq";
var footballerlevelToPassive = ["3052002","3052003"];
db.goals.find({
"footballer": footballerIdToPassive,
"footballerlevel": { "$in": footballerlevelToPassive }
})
which is equivalent to the query
db.goals.find({
"footballer": footballerIdToPassive,
"$or": [
{ "footballerlevel": "3052002" },
{ "footballerlevel": "3052003" }
]
})
Quick demo
Upvotes: 3