Mongo-Java-获取所有文档将字符串日期作为日期排序

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

只是想知道什么是最好的方法。以下代码需要能够以降序对字符串日期作为日期值进行排序,但需要分页。

documentList = collection.find().skip(skip).limit(limit).sort(Sorts.descending("ReceivedDate"));

除了排序不起作用外,其余的行也很有效。我仍然习惯于使用Mongo。认为最好找出正确的做事方法。早点养成好习惯。

与我发现的链接的不同之处在于,我在分页中添加了]。>

我查看了一些链接,但是并不确定100%使用find时需要什么。Sort by date string (ascending) on MongoMongoDB sorting date string (mm/dd/yyyy)

[我们试图用降序分页的典型文档是

{
"_id" : ObjectId("5ddc80b3adbe1d0001bc50f7"),
"ReceivedDate" : "20/12/2019",
"ReceivedTime" : "08:00:00",
"batch_id" : "112233",
"EventMessage" : "SUCCESS",
"Observations" : 1,
"DataSet" : "xxxx",
"SetType" : "yyy",
"SetName" : "yyyxxx",

}

非常感谢,罗素

只是想知道什么是最好的方法。以下代码需要能够以降序但以分页方式将字符串日期排序为日期值。 documentList = collection.find()。skip(...

java mongodb sorting date pagination
1个回答
0
投票

以下代码需要能够将字符串日期排序为日期值按降序排列,但带有分页。

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