Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple MongoDB query very slow although index is set
    text
    copied!<p>I've got a MongoDB collection that holds about 100M documents.</p> <p>The documents basically look like this:</p> <pre><code>_id : ObjectId("asd1234567890") _reference_1_id : ObjectId("fgh4567890123") _reference_2_id : ObjectId("jkl7890123456") name : "Test1" id : "4815162342" created_time : Date( 1331882436000 ) _contexts : ["context1", "context2"] ... </code></pre> <p>There are some indexes set, here's the output of <em>db.mycoll.getIndexes();</em></p> <pre><code>[ { "v" : 1, "key" : { "_id" : 1 }, "ns" : "mydb.mycoll", "name" : "_id_" }, { "v" : 1, "key" : { "_reference_1_id" : 1, "_reference_2_id" : 1, "id" : 1 }, "unique" : true, "ns" : "mydb.mycoll", "name" : "_reference_1_id_1__reference_2_id_1_id_1" }, { "v" : 1, "key" : { "_reference_1_id" : 1, "_reference_2_id" : 1, "_contexts" : 1, "created_time" : 1 }, "ns" : "mydb.mycoll", "name" : "_reference_1_id_1__reference_2_id_1__contexts_1_created_time_1" } ] </code></pre> <p>When I execute a query like</p> <pre><code>db.mycoll.find({"_reference_2_id" : ObjectId("jkl7890123456")}) </code></pre> <p>it takes over an hour (!) until it's finished, no matter if there are results or not. Any ideas?</p> <p><strong>Update:</strong> Here's what the output of</p> <pre><code>db.mycoll.find({"_reference_2_id" : ObjectId("jkl7890123456")}).explain(); </code></pre> <p>looks like:</p> <pre><code>{ "cursor" : "BasicCursor", "nscanned" : 99209163, "nscannedObjects" : 99209163, "n" : 5007, "millis" : 5705175, "nYields" : 17389, "nChunkSkips" : 0, "isMultiKey" : false, "indexOnly" : false, "indexBounds" : { } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload