无法对MongoDB 3.4上存储为值“Dtae(-62135596800000)”的日期字段进行排序

问题描述 投票:0回答:1

我正在使用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键降序对记录进行排序。我在这里错过了什么?

mongodb sorting mongodb-query
1个回答
1
投票

这是行不通的,因为Created包含Dates但这些数据没有正确存储。因此,首先存储适当的数据,然后尝试。另外,您可以在架构中添加timestamps: true。插入新记录时,它将存储ISODate(){ collection: 'user', timestamps: true }

© www.soinside.com 2019 - 2024. All rights reserved.