mongodb query find multiple values code example

Example 1: java mongodb find with multiple conditions

BasicDBObject criteria = new BasicDBObject();
criteria.append("color", "black");
criteria.append("shape", "round");
criteria.append("weight", 100);

DBCursor cur = widgets.find(criteria);

Example 2: mongoose find multiple conditions

User.find({$or:[{region: "NA"},{sector:"Some Sector"}]}, function(err, user) 
 {
    if (err)
    {
        res.send(err);
    }
    console.log(user);
    res.json(user);

 });

Example 3: mongodb find multiple fields

{ <field1>: <value>, <field2>: <value> ... }

Tags:

Java Example