mongodb find with 2 conditions code example

Example 1: mongodb aggregation $filter multiple conditions

cond: {
  $and: [
    { $gte: ['$$item.timestamp_start', fromTimestamp] },
    { $lt: ['$$item.timestamp_start', toTimestamp] }
  ]
}

Example 2: 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 3: mongodb find documents where two fields are equal

db.myCollection.find( { $where: "this.a1.a != this.a2.a" } )

Example 4: 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);

 });

Tags:

Go Example