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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -