我有以下类型的对象存储在mongodb中:
{ _id: 5319b78ba96ea4ef5c99dd55, name: 'Test',
channel: 'Right one', showed: { _isAMomentObject: true, _i: '12.3.2014 21:45', _f: 'DD.MM.YYYY HH:mm', _l: null, _strict: null, _isUTC: false, _pf: [Object], _a: [Object], _d: Wed Mar 12 2014 21:45:00 GMT-0400 (EDT), _isValid: true, _lang: [Object] } },
我想按日期顺序获取最后30个对象。我尝试过以这种方式排序(以及使用shows._d),似乎按字母顺序排序,而不是按日期排序。
db.open(function(err, db) {
var options = {
'limit': 30,
'sort': ['showed._i','desc']
}
db.collection('programs', function(err, collection) {
collection.find({}, options, function(err, docs) {
docs.toArray(function(err, docs) {
res.json(docs);
});
});
});
});