You can probably use aggregation framework to sort your data based on date. Here is what I tried and its working fine.
db.shouts.aggregate([
{ "$unwind": "$notifications"},
{ "$sort": { "notifications.created": -1 }},
{ "$group": { "_id": "$_id", "notifications": { "$push": "$notifications" }}}
]);
and the result is:
{
"_id" : ObjectId("5361e2cfbf5e5bf862400210"),
"notifications" : [
{
"type" : "Shout",
"created" : ISODate("2014-04-25T17:34:15.388Z")
},
{
"type" : "Shout",
"created" : ISODate("2014-04-24T13:37:02.678Z")
}
]
}
hope it helps