java - 如何根据结果内部对象对mongo聚合查询进行排序
问题描述
如果 mongo 聚合结果是:
{
_id : "5c1a39d182ceb728c3430275",
docs : {
"First Name": "Nilesh",
"Last Name" : "Sodha",
"Age" : 23
}
},
{
_id : "5c1a39d182ceb728c3430274",
docs : {
"First Name": "Pradip",
"Last Name" : "Sodha",
"Age" : 25
}
}
如何在JAVA中获得基于“年龄”的排序结果
解决方案
尝试这个
mongoTemplate.find(new Query(Criteria.where("_id").is(mongoId))
.with(new Sort(Sort.Direction.DESC, "Age")), eClass);
mongoId = 自动生成的 mongo id
推荐阅读
- c - 如何在C中的数组内定义函数?
- python - 在 Python 3 环境中使用 f2py 时出现错误“需要类似字节的对象,而不是 'str'”
- php - 我只想要 php laravel 中的手机号码范围,我在下面使用哪个?
- node.js - 如何在 AWS 云端托管 Node.js 服务器?我正在尝试制作社交媒体
- android - 如何在 Android Studio 中设置默认 NDK 的路径?
- c++ - 为什么 'std::cout << !+2 ' 输出 0?
- php - 在 url 中获取 basename
- sql - Microsoft SQL Server 与 Visual Studio.net 的连接错误(Windows 窗体)
- spring - 如何定义 StreamsBuilderFactoryBean 的两个实例
- python - view.py 中的 Django PasswordChangeForm 不起作用