Note that there are some explanatory texts on larger screens.

plurals
  1. POMongoDB $query operator ignores index?
    text
    copied!<p>I created a test MongoDB collection "sampleCollection" with documents which looks like:</p> <pre><code> "_id" : ObjectId("510929e041cb2179b41ace1c"), "stringField" : "Random string0", "longField" : NumberLong(886) </code></pre> <p>and has index on field "stringField". When I execute </p> <pre><code>db.sampleCollection.find({"stringField":"Random string0"}).explain() </code></pre> <p>everything is ok:</p> <pre><code> "cursor" : "BtreeCursor stringField_1", "isMultiKey" : false, "n" : 2, "nscannedObjects" : 2, "nscanned" : 2, "nscannedObjectsAllPlans" : 2, "nscannedAllPlans" : 2, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 0, "nChunkSkips" : 0, "millis" : 0, "indexBounds" : { "stringField" : [ [ "Random string0", "Random string0" ] ] } </code></pre> <p>but </p> <pre><code>db.sampleCollection.find({$query:{"stringField":"Random string0"}}).explain() </code></pre> <p>gets me</p> <pre><code>"cursor" : "BasicCursor", "isMultiKey" : false, "n" : 0, "nscannedObjects" : 4, "nscanned" : 4, "nscannedObjectsAllPlans" : 4, "nscannedAllPlans" : 4, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 0, "nChunkSkips" : 0, "millis" : 0, "indexBounds" : { } </code></pre> <p>This is not looks like a problem, but I'm using <strong>org.springframework.data.mongodb</strong> framework in production and usage of query constructions is an only way to write repositories. And thus I have a db which completely ignores indexed data.</p> <p>Is it correct? Or I misunderstood something?</p>
 

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