Tal vez pueda usar la agregación y una fecha de finalización artificialmente alta:
c = db.foo.aggregate([
{$project: {
next_time: 1,
nlt: { $ifNull: [ "$next_time", new ISODate("9000-01-01") ] }
}
}
,
{$sort: { "nlt": 1}}
]);
c.forEach(function(r) { printjson(r); });
Alternativamente, si la mayoría del material tiene valores nulos y no desea lidiar con esos documentos en absoluto, entonces fíltrelos y simplemente $sort
el resto:
db.foo.aggregate([
{$match: {"nt": {$exists: true}}}
,
{$sort: { "nt": 1}}
]);