mongodb search in multiple fields code example
Example 1: mongodb match multiple fields
$match:
{
$and: [
{'ExtraFields.value': {$in: ["A52A2A"]}},
{'ExtraFields.fieldID': ObjectId("5535627631efa0843554b0ea")}
]
}
Example 2: search with multiple field in node js mongodb
db.test.find({
$or:[
{
$and: [
{'stocknumber':12346},
{'model':'bmx'},
{'make':2002},
{'rego':'KA01HG6268'},
{'adate':'2017-10-01T05:07:10.969Z'},
{'cdate':'2017-10-01T05:07:10.969Z'}
]
},
{
$and: [
{'stocknumber':12347},
{'model':'bmy'},
{'make':2003}
]
}
]
}).pretty()