title: mongodb index works differently
body: <p>I do not understand if the index was executed with {createdAt: 1}.</p>
  
  <p>Should {device.objectId: 1} index be run?</p>
  
  <p>Sometimes this happens during many attempts.</p>
  
  <p>I know I need to walk a composite index.</p>
  
  <p>But</p>
  
  <p>Even if you do not have a composite index,</p>
  
  <p>We know that if the key used in the condition is contained in a single index, it searches for the optimal query execution condition.</p>
  
  <p>I want to know what caused it to work.</p>
  
  <p>I wonder why this result came out.</p>
  
  <p><strong>The currently set index.</strong></p>
  
  <pre><code>[
      {
          "v" : 1,
          "key" : {
              "_id" : 1
          },
          "name" : "_id_",
          "ns" : "1000009494.QuestItemLog"
      },
      {
          "v" : 1,
          "key" : {
              "createdAt" : 1
          },
          "name" : "createdAt_1",
          "ns" : "1000009494.QuestItemLog",
          "background" : 1
      },
      {
          "v" : 1,
          "key" : {
              "updatedAt" : 1
          },
          "name" : "updatedAt_1",
          "ns" : "1000009494.QuestItemLog",
          "background" : 1
      },
      {
          "v" : 1,
          "key" : {
              "device.objectId" : 1
          },
          "name" : "device.objectId_1",
          "ns" : "1000009494.QuestItemLog",
          "background" : 1
      },
      {
          "v" : 1,
          "key" : {
              "content.objectId" : 1
          },
          "name" : "content.objectId_1",
          "ns" : "1000009494.QuestItemLog",
          "background" : 1
      }
  ]
  </code></pre>
  
  <p><strong>The query log in question.</strong></p>
  
  <pre><code>2018-06-12T14:04:58.433+0900 [conn199770] query 1000009494.QuestItemLog query: { query: { $and: [ { device.objectId: "5aecd3610cf237a6838337f9" }, { content.objectId: "58f7521fc8f235c33d505e22" }, { $or: [ { ACL.5aecd3dd0cf2716ac95a6d1d.read: true }, { ACL.role:r_01035284674.read: true }, { ACL.*.read: true }, { ACL: null } ] } ] }, orderby: { createdAt: -1 }, $readPreference: { mode: "secondaryPreferred" } }
   planSummary: IXSCAN { createdAt: 1 } ntoskip:0 nscanned:7913847 nscannedObjects:7913847 keyUpdates:0 numYields:46505 locks(micros) r:173389865 nreturned:0 reslen:20 562751ms
  </code></pre>
  
  <p><strong>row count</strong></p>
  
  <pre><code>shard01:SECONDARY&gt; db.QuestItemLog.find({"content.objectId":"58f7521fc8f235c33d505e22"}).explain();
  {
      "cursor" : "BtreeCursor content.objectId_1",
      "isMultiKey" : false,
      "n" : 5095,
      "nscannedObjects" : 5095,
      "nscanned" : 5095,
      "nscannedObjectsAllPlans" : 5095,
      "nscannedAllPlans" : 5095,
      "scanAndOrder" : false,
      "indexOnly" : false,
      "nYields" : 1865,
      "nChunkSkips" : 0,
      "millis" : 5236,
      "indexBounds" : {
          "content.objectId" : [
              [
                  "58f7521fc8f235c33d505e22",
                  "58f7521fc8f235c33d505e22"
              ]
          ]
      },
      "server" : "BPP-BAAS-MONGO104:27017",
      "filterSet" : false
  }
  
  shard01:SECONDARY&gt; db.QuestItemLog.find({"device.objectId":"5aecd3610cf237a6838337f9"}).explain();
  {
      "cursor" : "BtreeCursor device.objectId_1",
      "isMultiKey" : false,
      "n" : 153,
      "nscannedObjects" : 153,
      "nscanned" : 153,
      "nscannedObjectsAllPlans" : 153,
      "nscannedAllPlans" : 153,
      "scanAndOrder" : false,
      "indexOnly" : false,
      "nYields" : 1,
      "nChunkSkips" : 0,
      "millis" : 0,
      "indexBounds" : {
          "device.objectId" : [
              [
                  "5aecd3610cf237a6838337f9",
                  "5aecd3610cf237a6838337f9"
              ]
          ]
      },
      "server" : "BPP-BAAS-MONGO104:27017",
      "filterSet" : false
  }
  </code></pre>