我正在使用Robo 3T从MongoDB 3.4中获取数据。我有一个集合,其中日期时间存储为一些数字值,如“-62135596800000”。收集:{
"_id" : ObjectId("5a8eaf90e97a220a145dbf20"),
"Receiver" : "[email protected]",
"ReceiverName" : null,
"Codes" : [],
"Status" : 3,
"Failurs" : 0,
"Language" : 1,
"Created" : Date(-62135596800000),
"CouponId" : ObjectId("5a8eaf90e97a220a145dbf1e")
}
我想用Created descending对这个colelction的数据进行排序。我尝试使用查询:
db.getCollection('Emails').find().sort({"Created": -1}).limit(10)
但它不会根据Created
键降序对记录进行排序。我在这里错过了什么?
这是行不通的,因为Created
包含Dates但这些数据没有正确存储。因此,首先存储适当的数据,然后尝试。另外,您可以在架构中添加timestamps: true
。插入新记录时,它将存储ISODate()
。 { collection: 'user', timestamps: true }