【发布时间】:2012-11-30 15:06:54
【问题描述】:
我正在使用带有 Node.JS 的 MongoDB。我有一个包含日期和其他行的集合。日期是一个 JavaScript Date 对象。
我如何按日期排序这个集合?
【问题讨论】:
-
simple , collection.find().sort({datefield: 1}, function(err, cursor){...});或者你也可以使用 collection.find().sort({datefield: -1}, function(err, cursor){...});
-
请注意,您可能不需要
date列:stackoverflow.com/questions/5125521/…