|
Here's the sort with and index:
> db.g.ensureIndex({a: 1})
|
> db.g.find().sort({a:-1})
|
{ "_id" : ObjectId("4f88436904495dab8a55071c"), "a" : [ 4 ] }
|
{ "_id" : ObjectId("4f88436804495dab8a55071b"), "a" : [ 3 ] }
|
{ "_id" : ObjectId("4f88436704495dab8a55071a"), "a" : [ 2 ] }
|
{ "_id" : ObjectId("4f88441104495dab8a550720"), "a" : [ 1, 1, 1, 1 ] }
|
{ "_id" : ObjectId("4f88440204495dab8a55071f"), "a" : [ 1, 1, 0, 1 ] }
|
{ "_id" : ObjectId("4f88439c04495dab8a55071e"), "a" : [ 1, 1, 0 ] }
|
{ "_id" : ObjectId("4f88438604495dab8a55071d"), "a" : [ 1, 1 ] }
|
{ "_id" : ObjectId("4f88436504495dab8a550719"), "a" : [ 1 ] }
|
|
> db.g.find().sort({a:1})
|
{ "_id" : ObjectId("4f88439c04495dab8a55071e"), "a" : [ 1, 1, 0 ] }
|
{ "_id" : ObjectId("4f88440204495dab8a55071f"), "a" : [ 1, 1, 0, 1 ] }
|
{ "_id" : ObjectId("4f88436504495dab8a550719"), "a" : [ 1 ] }
|
{ "_id" : ObjectId("4f88438604495dab8a55071d"), "a" : [ 1, 1 ] }
|
{ "_id" : ObjectId("4f88441104495dab8a550720"), "a" : [ 1, 1, 1, 1 ] }
|
{ "_id" : ObjectId("4f88436704495dab8a55071a"), "a" : [ 2 ] }
|
{ "_id" : ObjectId("4f88436804495dab8a55071b"), "a" : [ 3 ] }
|
{ "_id" : ObjectId("4f88436904495dab8a55071c"), "a" : [ 4 ] }
|
Neither of these examples follows that rule. In both index and unindexed descending sorts, the arrays containing a '0' are not the final arrays to appear.
|