0

I have the following query to be executed on my MongoDB collection order_error. It has over 60 million documents. The main concern is I am having a $in operator within my query. I tried several possibilities of indices but none of them gave a high-performance improvement. The query is as follows

db.getCollection("order_error").find({
   "$and":[
      {
         "type":"order"
      },
      {
         "Origin.SN":{
            "$in":[
               "4095",
               "4100",
               "4509",
               "4599",
               "4510"
            ]
         }
      }
   ]
}).sort({"timestamp.milliseconds" : 1}).skip(1).limit(100).explain("executionStats")

One issue that needs to be noted is I am allowing sort on timestamp.milliseconds in both directions(ASC + DESC). I have limited the entries within the $in. Usually, it is more. SO what kind of index gives the performance improvement. I tried creating the following indices already

type_1_Origin.SN_1_timestamp.milliseconds_-1
type_1_timestamp.milliseconds_-1_Origin.SN

Is there any better way for index creation?

James Z
  • 12,209
  • 10
  • 24
  • 44

0 Answers0