title: How can I reduce time spent acquiring the mongodb schema lock?
body: <p>We have a mongodb cluster, backed by WiredTiger, in production, with a 3 node replica set consisting of a master and two slaves.  One of the slaves has another service co-located that queries the slave extensively.  In addressing some slowness in the co-located service I'm seeing a lot of surprisingly slow queries.  This one took 3.3 seconds:</p>
  
  <pre><code>  find: "myColl",
    filter: { myField: "myValue" },
    projection: { name: 1 },
    $db: "myDb",
    $clusterTime: { clusterTime: Timestamp(1568198047, 3), signature: { hash: BinData(0, 0000000000000000000000000000000000000000), keyId: 0 } },
    lsid: { id: UUID("2ed823aa-e6af-4898-a4c1-c039d28a32ab") },
    $readPreference: { mode: "secondary" } }
    planSummary: IXSCAN { myField: 1 } keysExamined:0 docsExamined:0 cursorExhausted:1 numYields:0 nreturned:0 reslen:232
    locks:{ Global: { acquireCount: { r: 1 } },
            Database: { acquireCount: { r: 1 } },
            Collection: { acquireCount: { r: 1 } } }
    storage:{ data: { bytesRead: 355, timeReadingMicros: 4 }, timeWaitingMicros: { schemaLock: 3284692 }
  </code></pre>
  
  <p>The line that stands out to me here, is the last one, indicating that it spends 99.9% of its time waiting to acquire something called a schema lock.</p>
  
  <p>I checked this particular database and collection and it turns out the collection had 50 items at query time.  Furthermore, there's also an index on <code>myField</code>.</p>
  
  <p>Why is a read query waiting to acquire a schema lock?  What can I do to eliminate this long wait?</p>