MongoDB use $and with $or operator in the same query -
hi want set filter collection on mongodb.
i want set filter (code field startswith "0" or "2") , (firmid eq "5186224fdff7421bd4552f7f")
but query result null. wrong?
my mongo query is;
db.customers.find({ "$and" : [{ "firmid" : objectid("5186224fdff7421bd4552f7f") }, { "$or" : [{ "code" : /^0/ }, { "code" : /^2/ }] }] })
_
{ $and: [ { "firmid": objectid("5186224fdff7421bd4552f7f") }, { "$or": [ { "code": /^0/ }, { "code": /^2/ } ] } ] }
or use
{ "firmid": objectid("5186224fdff7421bd4552f7f"), "$or": [ { "code": /^0/ }, { "code": /^2/ } ] }
you should not using either $and
nor $or
here.
{ firmid: objectid("xxx"), code:/^[02]/ }
if don't results possibly no records match criteria.
Comments
Post a Comment