[SERVER-11278] indexOnly false when query should be covered Created: 18/Oct/13  Updated: 10/Dec/14  Resolved: 19/Oct/13

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 2.4.6
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: David Wartell Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux


Operating System: Linux
Steps To Reproduce:

db.Test.insert(

{"_id" : ObjectId("5261ac33e4b070ca9e1480d1"), "date" : ISODate("2013-10-18T21:46:27.476Z"), "disabled" : false, "userHidden" : false, "postId" : NumberLong(103)}

)

db.Test.ensureIndex(

{ "postId" : 1, "userHidden" : 1, "disabled" : 1, "date" : -1}

,

{name: "findByPostId", sparse: true, unique: false}

)

db.Test.find( { $query:

{postId: 103, userHidden: false, disabled: false}

, $orderby:

{date: -1}

, $hint: "findByPostId", $explain: 1 },

{postId: 1, userHidden: 1, disabled: 1, date: 1 }

).pretty()

{
"cursor" : "BtreeCursor findByPostId",
"isMultiKey" : false,
"n" : 1,
"nscannedObjects" : 1,
"nscanned" : 1,
"nscannedObjectsAllPlans" : 1,
"nscannedAllPlans" : 1,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"indexBounds" : {
"postId" : [
[
103,
103
]
],
"userHidden" : [
[
false,
false
]
],
"disabled" : [
[
false,
false
]
],
"date" : [
[

{ "$maxElement" : 1 }

,

{ "$minElement" : 1 }

]
]
},
"allPlans" : [
{
"cursor" : "BtreeCursor findByPostId",
"n" : 1,
"nscannedObjects" : 1,
"nscanned" : 1,
"indexBounds" : {
"postId" : [
[
103,
103
]
],
"userHidden" : [
[
false,
false
]
],
"disabled" : [
[
false,
false
]
],
"date" : [
[

{ "$maxElement" : 1 }

,

{ "$minElement" : 1 }

]
]
}
}
],
"server" : "test-mongo.luvit.net:270"
}

According to docs and everything I can find there is no reason this query should not be indexOnly: true and it is false

Participants:

 Description   

Index does not have fields that are sub documents or arrays and indexOnly is false on what should be a covered query



 Comments   
Comment by David Wartell [ 18/Oct/13 ]

Please CLOSE. Not a bug.

Apologies I was convinced this was a bug.

This was the problem:
http://docs.mongodb.org/manual/tutorial/create-indexes-to-support-queries/#indexes-covered-queries
By default, MongoDB includes the _id field in the query result. So, if the index does not include the _id field, then you must exclude the _id field (i.e. _id: 0) from the query results.

By adding _id: 0 to the projection I get indexOnly true

Generated at Thu Feb 08 03:25:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.