0
votes

I want to run a query like so:

db.sent.find({trigger_id:ObjectId("516f029ac5f4810002000007"), created_at: {$gte: ISODate("2013-04-01T00:00:00.000Z"), $lt: ISODate("2013-05-01T00:00:00.000Z")}}).count()

but where the ObjectID("516f029ac5f4810002000007") is, I wish that to be a number of different values and for mongo to pull out records that match ANY of the values.

How do I do this? THanks!

2

2 Answers

1
votes

You can use the MongoDB $in operator:

db.sent.find({
    trigger_id: { 
         $in: [
             ObjectId("516f029ac5f4810002000007"),
             ObjectId("516f029ac5f4810002000008"),
             ObjectId("516f029ac5f4810002000009"),
         ]
    }, 
    created_at: {
         $gte: ISODate("2013-04-01T00:00:00.000Z"), 
         $lt: ISODate("2013-05-01T00:00:00.000Z")
    }
}).count()
0
votes

You can use the $in operator:

db.sent.find( { trigger_id: { $in: [ <value1>, <value2>, ... <valueN> ] },
                created_at: {$gte: ISODate("2013-04-01T00:00:00.000Z"), $lt: ISODate("2013-05-01T00:00:00.000Z") } } ).count() 

Here's more information on the $in operator

http://docs.mongodb.org/manual/reference/operator/in/#op._S_in