mongodb 2.4.9排序不起作用

时间:2014-03-19 02:00:06

标签: mongodb sorting date text format

我有一个包含多个字段的简单集合。

日期字段是统一格式的文本字段" yyyy-MM-dd"。它不是DATE字段。 如下所示,我运行查询两次。一旦降序排序,升序一次,但两者都返回相同的结果。

sort似乎可以与其他文本字段一起使用。 HELP !!!!!

> db.Moves.find({}, {_id :0, date: 1}).sort({date :0})
{ "date" : "2012-12-01" }
{ "date" : "2012-12-04" }
{ "date" : "2012-12-05" }
{ "date" : "2012-12-10" }
{ "date" : "2012-12-19" }
{ "date" : "2012-12-28" }
{ "date" : "2012-12-31" }
{ "date" : "2013-01-07" }
{ "date" : "2013-01-21" }
{ "date" : "2013-01-22" }
{ "date" : "2013-01-31" }
{ "date" : "2013-02-01" }
{ "date" : "2013-02-04" }
{ "date" : "2013-02-07" }
{ "date" : "2013-02-11" }
{ "date" : "2013-02-11" }
{ "date" : "2013-02-20" }
{ "date" : "2013-02-25" }
{ "date" : "2013-02-26" }
{ "date" : "2013-03-04" }
Type "it" for more
> db.Moves.find({}, {_id :0, date: 1}).sort({date :1})
{ "date" : "2012-12-01" }
{ "date" : "2012-12-04" }
{ "date" : "2012-12-05" }
{ "date" : "2012-12-10" }
{ "date" : "2012-12-19" }
{ "date" : "2012-12-28" }
{ "date" : "2012-12-31" }
{ "date" : "2013-01-07" }
{ "date" : "2013-01-21" }
{ "date" : "2013-01-22" }
{ "date" : "2013-01-31" }
{ "date" : "2013-02-01" }
{ "date" : "2013-02-04" }
{ "date" : "2013-02-07" }
{ "date" : "2013-02-11" }
{ "date" : "2013-02-11" }
{ "date" : "2013-02-20" }
{ "date" : "2013-02-25" }
{ "date" : "2013-02-26" }
{ "date" : "2013-03-04" }
Type "it" for more
> 

0 个答案:

没有答案