title: Mongodb Sorting Desc for _id field very slow
body: <p>I have a mongodb database which has 30 million Dictionary and Each day of month has 1 million rows so all of document count 30x1=30 Million, database just has data for 1 month and i want to list and sort desc records of between 2018-07-01 and 2018-07-03 so i have 2 million rows between of that two days My each collection like below:</p>
  
  <pre><code>{
  "_id":"5c66cf5b67011aa76ca597b6",
  "timestamp":"2018-07-01 15:45:37.000",
  "category":"category_1"
  }
  </code></pre>
  
  <p>I added sorting desc index for timestamp column</p>
  
  <p>When i try sort asc i get response 0,1 seconds but i try sort desc i am getting response 702 seconds </p>
  
  <p>I am building python</p>
  
  <pre><code>from pymongo import MongoClient
  import datetime
  import time
  client = MongoClient()
  client = MongoClient('localhost', 27017)
  db = client.MongoBencmarkTestDB
  
  indicator_collections = db.IndicatorCollections
  
  dstart = datetime.datetime(2018, 7, 1,0, 0, 0)
  dfinish = datetime.datetime(2018, 7, 3,0, 0, 0)
  
  for indicator_collection in indicator_collections.find({
      "$and":
          [
              {
                  "timestamp": {"$lte": dfinish, "$gte": dstart}
              },
          ]
  
  }).sort([("_id", -1)]).skip(0).limit(1000):
      print(indicator_collection['_id'])
  </code></pre>
  
  <p>When i explain _id field for sorting desc: </p>
  
  <pre><code>db.IndicatorCollections.find().sort({_id : -1}).explain()
  </code></pre>
  
  <p>Getting response: </p>
  
  <pre><code>{
      "queryPlanner" : {
          "plannerVersion" : 1,
          "namespace" : "MongoBencmarkTestDB.IndicatorCollections",
          "indexFilterSet" : false,
          "parsedQuery" : {
  
          },
          "winningPlan" : {
              "stage" : "FETCH",
              "inputStage" : {
                  "stage" : "IXSCAN",
                  "keyPattern" : {
                      "_id" : 1
                  },
                  "indexName" : "_id_",
                  "isMultiKey" : false,
                  "multiKeyPaths" : {
                      "_id" : [ ]
                  },
                  "isUnique" : true,
                  "isSparse" : false,
                  "isPartial" : false,
                  "indexVersion" : 2,
                  "direction" : "backward",
                  "indexBounds" : {
                      "_id" : [
                          "[MaxKey, MinKey]"
                      ]
                  }
              }
          },
          "rejectedPlans" : [ ]
      },
      "serverInfo" : {
          "host" : "reterius-pc-MacBook-Pro.local",
          "port" : 27017,
          "version" : "4.0.3",
          "gitVersion" : "7ea530946fa7880364d88c8d8b6026bbc9ffa48c"
      },
      "ok" : 1
  }
  </code></pre>
  
  <p>My indexes:</p>
  
  <pre><code>[
      {
          "v" : 2,
          "key" : {
              "_id" : 1
          },
          "name" : "_id_",
          "ns" : "MongoBencmarkTestDB.IndicatorCollections"
      },
      {
          "v" : 2,
          "key" : {
              "timestamp" : -1
          },
          "name" : "timestamp_-1",
          "ns" : "MongoBencmarkTestDB.IndicatorCollections"
      }
  ]
  </code></pre>
  
  <p>I want to get response quickly because its very important.</p>