I have a mongo collection with documents like-
{
_id : 1abc,
'data' :'blah',
'createdDate' : ISODate("2013-05-26T01:34:10Z"),
'a': [
{
_id : a1adas,
'createdDate' : ISODate("2013-05-26T01:35:10Z"),
'b':[
{
_id : aadaasd
'createdDate' : ISODate("2013-05-26T01:37:10Z"),
}
]
}
]
}
I am required to sort the documents in reverse chronological order so that the document with the most recent createdDate , at any level, is first.
So far, I have this query, which I am not sure is working as expected.
db.collection.find({'data':'blah'}).sort({'createdDate':-1, 'a.createdDate': -1, 'a.b.createdDate': -1 }).explain();
I would like to know if there is a more efficient way of performing such a sort.