如何基于结果内部对象对mongo聚合查询进行排序

时间:2019-01-14 07:21:33

标签: java spring mongodb spring-boot spring-mvc

如果mongo聚合结果为:

{
  _id : "5c1a39d182ceb728c3430275",
  docs : {
    "First Name": "Nilesh",
    "Last Name" : "Sodha",
    "Age"       : 23    
  }
},

{
  _id : "5c1a39d182ceb728c3430274",
  docs : {
    "First Name": "Pradip",
    "Last Name" : "Sodha",
    "Age"       : 25    
  }
}

如何在JAVA中基于“年龄”获得排序结果

1 个答案:

答案 0 :(得分:1)

尝试一下

 mongoTemplate.find(new Query(Criteria.where("_id").is(mongoId))
                    .with(new Sort(Sort.Direction.DESC, "Age")), eClass);
  

mongoId =自动生成的mongo id

相关问题