0

I have documents in mongodb which has a transaction_id. Data type of transaction_id is ObjectId.

If I do below query, I get the document:

db.collection.find({ 'transaction_id': ObjectId('609cfef4ad16361274eb12e2') })
   .projection({})
   .sort({_id:-1})
   .limit(100)

But what if I want to get all the documents for multiple transaction ids. So I did:

db.collection.find({ 'transaction_id': [ObjectId('609cfef4ad16361274eb12e2'), ObjectId('609cfeecad16361274eb12e1')] })
   .projection({})
   .sort({_id:-1})
   .limit(100)

I get no documents. How can I get all the documents for matching transaction ids. Thanks

S Andrew
  • 5,592
  • 27
  • 115
  • 237

1 Answers1

1

You can use in operator:

db.collection.find( { 'transaction_id': { $in: [ObjectId('609cfef4ad16361274eb12e2'), ObjectId('609cfeecad16361274eb12e1')] } } )
Raymond Reddington
  • 1,709
  • 1
  • 13
  • 21