MongoDB日期排序不起作用

时间:2015-02-26 09:19:44

标签: mongodb sorting date

我正在使用mongo 2.4.10。数据库中的日期存储在ISO format'2015-02-16T09:00:00+0500')中。 datetime字段也有索引。

但是当我尝试按日期排序时 - DB会返回错误的排序数据。我认为它应该考虑日期时间字符串末尾的时区吗?如何强迫它与时区一起工作?

db.appointments.find().sort({datetime: -1})
{ "_id" : ObjectId("54db6562266aa1250e000006"), "created_at" : "2015-02-11 16:21:22", "datetime" : "2015-02-16T11:00:00+0400", "doctor_id" : ObjectId("5490149f266aa13a6f000115"), "patient_id" : ObjectId("54901307266aa1816f000001"), "status" : "confirmed", "updated_at" : "2015-02-11T16:25:51+0200", "visitreasons" : [  ObjectId("54cb6738266aa14a71000018") ] }
{ "_id" : ObjectId("54d0e460266aa1564f000003"), "created_at" : "2015-01-31 15:46:05", "datetime" : "2015-02-16T09:00:00+0500", "doctor_id" : ObjectId("549031ca266aa16b7600009c"), "patient_id" : ObjectId("54901307266aa1816f000002"), "status" : "Pending", "updated_at" : "2015-01-31 15:46:05", "visitreasons" : [  ObjectId("54cb6738266aa14a71000018") ] }
{ "_id" : ObjectId("54ccdc9d266aa1093c000003"), "created_at" : "2015-01-31 15:46:05", "datetime" : "2015-02-16T05:00:00+0000", "doctor_id" : ObjectId("549031ca266aa16b7600009c"), "patient_id" : ObjectId("54901307266aa1816f000001"), "status" : "Pending", "updated_at" : "2015-02-26T11:05:43+0200", "visitreasons" : [  ObjectId("54cb6738266aa14a71000018") ] }

0 个答案:

没有答案