mongodb client node js find multiple code example

Example 1: search with multiple field in node js mongodb

> db.test.find({$or: [{Description: {$regex: '^225/65R16'}, Brand: {$regex: '^Hankook'}}]})
{ "Description" : "225/65R16 71T K715", "Brand" : "Hankook", "Ref" : 123455 }
{"Description" : "225/65R16 94T", "Brand" : "Hankook", "Ref" : 123455 }

> db.test.find({$or: [{Description: {$regex: '^225'}, Brand: {$regex: '^Han'}}]})
{ "Description" : "225/65R16 71T K715", "Brand" : "Hankook", "Ref" : 123455 }
{ "Description" : "225/65R16 94T", "Brand" : "Hankook", "Ref" : 123455 }

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()

Tags:

Misc Example