-
Type: Bug
-
Resolution: Duplicate
-
Priority: Critical - P2
-
None
-
Affects Version/s: 2.6.5
-
Component/s: Index Maintenance, Querying
-
None
-
ALL
Hello,
I encountered a strange behavior in Mongo 2.6.x. i am using Mongoid in ruby talk to MongoDB and Mongoid allows having default sort command. When I run the following command :
Person.find("someindex") in Mongoid, it is translated into
db.persons.find(
).sort(created_at: -1)
Mongoid is not really smart by generating such query because we know we will get either 0 or 1 result, so the sort operator does not make sense.
However, I've found cases where MongoDB is even less smart and caches the wrong index, including the created_at field.
I would expect MongoDB to automatically use the _id index whenever it is present in the query, no matter other fields that are present in the query, in partcular sort commands.
I already had a discussion about this on google group:
https://groups.google.com/forum/#!searchin/mongodb-user/rpechayr/mongodb-user/-btb_43ONfk/w0dMlECPInIJ
- duplicates
-
SERVER-15802 Query optimizer should always use equality predicate over unique index when possible
- Closed
- related to
-
SERVER-13211 Optimal index not chosen for query plan when many indexes match same prefix
- Closed
-
SERVER-15225 CachedPlanStage should execute for trial period and re-plan if query performs poorly
- Closed