-
Type:
Bug
-
Resolution: Duplicate
-
Priority:
Major - P3
-
None
-
Affects Version/s: 2.4.12
-
Component/s: Shell
-
None
-
ALL
-
-
None
-
None
-
None
-
None
-
None
-
None
-
None
Consider the following code:
t = db.t;
t.drop();
t.ensureIndex({a: 1});
t.ensureIndex({b: 1});
t.find({$query: {a: 1}, $orderby: {b: -1}}).explain()
This should error with a useful message. a 2.4 server does not raise an error, whereas a 2.6 server raises an unhelpful error message. Instead, the shell could raise a useful error before sending the query to the server.
Original Description
I don't know if this is a bug, but the following two queries result in completely different outputs. The first output shows a full table scan whereas the second one claims to make use of the index. Which one is correct?
query 1:
db.java.find({ "$query" : { "a" : 1} , "$orderby" : { "b" : -1}}).explain()
{
"cursor" : "BasicCursor",
"isMultiKey" : false,
"n" : 0,
"nscannedObjects" : 100,
"nscanned" : 100,
"nscannedObjectsAllPlans" : 100,
"nscannedAllPlans" : 100,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"indexBounds" : {},
"server" : "XXXX"
}
query 2:
db.java.find({ "$query" : { "a" : 1} , "$orderby" : { "b" : -1}, "$explain" : true})
/* 0 */
{
"cursor" : "BtreeCursor a_1",
"isMultiKey" : false,
"n" : 6,
"nscannedObjects" : 6,
"nscanned" : 6,
"nscannedObjectsAllPlans" : 19,
"nscannedAllPlans" : 19,
"scanAndOrder" : true,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"indexBounds" : {
"a" : [
[
1,
1
]
]
},
"allPlans" : [
{
"cursor" : "BtreeCursor b_1 reverse",
"n" : 0,
"nscannedObjects" : 7,
"nscanned" : 7,
"indexBounds" : {
"b" : [
[
{
"$maxElement" : 1
},
{
"$minElement" : 1
}
]
]
}
},
{
"cursor" : "BtreeCursor a_1",
"n" : 6,
"nscannedObjects" : 6,
"nscanned" : 6,
"indexBounds" : {
"a" : [
[
1,
1
]
]
}
},
{
"cursor" : "BasicCursor",
"n" : 0,
"nscannedObjects" : 6,
"nscanned" : 6,
"indexBounds" : {}
}
],
"oldPlan" : {
"cursor" : "BtreeCursor a_1",
"indexBounds" : {
"a" : [
[
1,
1
]
]
}
},
"server" : "nbwinviemg:27017"
}
- duplicates
-
SERVER-6767 Interpret $query as special so you can copy profiler/logged queries into shell
-
- Closed
-