For the or query of mongodb, please consult as follows:
Sql approacha='x' and b='x' or ( c in (3,2) )
Mongo’s result is to inquire first.c in(3,2)
Then the relevant filtering is carried out.
Is there something wrong with my writing, or is mongo itself not very supportive?
My current writing style is:
db.getCollection('vip_gindex').find({
'status': 1,
$or: [{
'id': {
$in: [305898, 433975]
}
}]
})
As a result, only two of them were seriously investigated and dealt with.
Your writing means:
status = 1 AND id IN (305898, 433975)
$or
There is no practical meaning, because it is$or
Each element in the following array is a condition, and you only gave one element.
According to what you wanta='x' AND b='x' OR ( c IN (3,2) )
Should be:
db.getCollection('vip_gindex').find({ $or: [{ a: 'x', b: 'x' }, { c: { $in: [3, 2] } }] });
The writing style upstairs is also right, but it’s complicated.