title: Mongodb query exceptionally slow
body: <p>My mongodb is rather simple: a dataset/entry has around 30 properties on 3 layers. One such entry has up to around 5000 characters. I have 500k of them.
  When I execute the following query...</p>
  
  <pre><code>db.images.find({ "featureData.cedd": { $exists: false}}).count()
  </code></pre>
  
  <p>...it is extremely slow. It's not indexed, but still.. from my MySQL experience it shouldn't take <strong>20 minutes</strong> to execute one such query.</p>
  
  <p>While being executed (directly on the mongo terminal) there's 3% CPU usage and still over 2 Gigs of free memory.</p>
  
  <p>Thanks for giving me a hint on what I could do!</p>
  
  <p>EDIT: An explain() of the query (without count) gives:</p>
  
  <pre><code>db.images.find({ "featureData.cedd": { $exists: false }}).explain()
  {
      "cursor" : "BasicCursor",
      "nscanned" : 532537,
      "nscannedObjects" : 532537,
      "n" : 438,
      "millis" : 1170403,
      "nYields" : 0,
      "nChunkSkips" : 0,
      "isMultiKey" : false,
      "indexOnly" : false,
      "indexBounds" : {
  
      }
  }
  </code></pre>
  
  <p>Output of iostat:</p>
  
  <pre><code>Linux 3.2.0-58-generic (campartex)      03/25/2014      _x86_64_        (2 CPU)
  
  avg-cpu:  %user   %nice %system %iowait  %steal   %idle
            34.93    0.01    0.25    0.48    0.00   64.33
  
  Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
  sda               2.08       103.79        11.26  172805914   18749067
  fd0               0.00         0.00         0.00        148          0
  </code></pre>
  
  <p>Output of explain() <strong>after adding an index</strong>:</p>
  
  <pre><code>db.images.find({ "featureData.cedd": { $exists: false }}).explain()
  {
      "cursor" : "BtreeCursor featureData.cedd_1",
      "nscanned" : 438,
      "nscannedObjects" : 438,
      "n" : 438,
      "millis" : 2,
      "nYields" : 0,
      "nChunkSkips" : 0,
      "isMultiKey" : true,
      "indexOnly" : false,
      "indexBounds" : {
              "featureData.cedd" : [
                      [
                              null,
                              null
                      ]
              ]
      }
  }
  </code></pre>