>db.test.drop()
|
>db.test.insert([{a:[{b:{c:3}}, 1]}, {a:[{b:{c:5}},1]}, {a:[{b:{c:4}},1]}])
|
>db.test.find().sort({'a.b.c':1})
|
{ "_id" : ObjectId("5339c1f58b8794d6f2676019"), "a" : [ { "b" : { "c" : 3 } }, 1 ] }
|
{ "_id" : ObjectId("5339c1f58b8794d6f267601a"), "a" : [ { "b" : { "c" : 5 } }, 1 ] }
|
{ "_id" : ObjectId("5339c1f58b8794d6f267601b"), "a" : [ { "b" : { "c" : 4 } }, 1 ] }
|
should the {a:[{b:{c:5}},1]} be the last doc? They do if they don't have the 1 in the array.
>db.test.drop()
|
>db.test.insert([{a:[{b:{c:3}}]}, {a:[{b:{c:5}}]}, {a:[{b:{c:4}}]}])
|
>db.test.find().sort({'a.b.c':1})
|
{ "_id" : ObjectId("5339d2a26d764829de404bec"), "a" : [ { "b" : { "c" : 3 } } ] }
|
{ "_id" : ObjectId("5339d2a26d764829de404bee"), "a" : [ { "b" : { "c" : 4 } } ] }
|
{ "_id" : ObjectId("5339d2a26d764829de404bed"), "a" : [ { "b" : { "c" : 5 } } ] }
|