[SERVER-8638] Allowed to build {<field>:0} index Created: 20/Feb/13  Updated: 08/Mar/13  Resolved: 20/Feb/13

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: 2.2.2
Fix Version/s: None

Type: Bug Priority: Trivial - P5
Reporter: Anton V. Volokhov Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: indexes
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

osx 10.8, ubuntu 12.10, ubuntu 10.10


Issue Links:
Duplicate
duplicates SERVER-5826 Creating an index using a non-existin... Closed
duplicates SERVER-769 Validate top-level & index spec field... Closed
Operating System: ALL
Steps To Reproduce:

1 db.some.insert(

{a:1}

)
2 db.some.ensureIndex(

{a:0}

)
3 db.some.find().sort(

{a:1}

).explain()
4 db.some.find().sort(

{a:-1}

).explain()

Participants:

 Description   

it is allowed to create an

{a:0}

index. This index has unexpected behavior with sorting

> db.some.insert(

{a:1}

)
> db.some.ensureIndex(

{a:0}

)
> db.some.find().sort(

{a:1}

)

{ "_id" : ObjectId("51254055e6f520cff750a549"), "a" : 1 }

> db.some.find().sort(

{a:1}

).explain()
{
"cursor" : "BtreeCursor a_0 reverse",
"isMultiKey" : false,
"n" : 1,
"nscannedObjects" : 1,
"nscanned" : 1,
"nscannedObjectsAllPlans" : 1,
"nscannedAllPlans" : 1,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"indexBounds" : {
"a" : [
[

{ "$maxElement" : 1 }

,

{ "$minElement" : 1 }

]
]
},
"server" : "logab-osx.local:27017"
}
> db.some.find().sort(

{a:-1}

).explain()
{
"cursor" : "BtreeCursor a_0 reverse",
"isMultiKey" : false,
"n" : 1,
"nscannedObjects" : 1,
"nscanned" : 1,
"nscannedObjectsAllPlans" : 1,
"nscannedAllPlans" : 1,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 0,
"indexBounds" : {
"a" : [
[

{ "$maxElement" : 1 }

,

{ "$minElement" : 1 }

]
]
},
"server" : "logab-osx.local:27017"
}
>



 Comments   
Comment by Scott Hernandez (Inactive) [ 20/Feb/13 ]

That creates an ascending index, as you can see. This is how it works now since we don't validate the order.

There are other issues which describe this behavior and ask for better validation or for errors to be generated, for example.

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