java.lang.IllegalArgumentException: Expected unique result or null, but got more than one! - Spring Data Mongo

前端 未结 2 1737
逝去的感伤
逝去的感伤 2021-01-16 23:38

I\'m usingSpring Boot v2.2.2.RELEASE and Spring Data MongoDB. In this example, I am looking perform group by department code and get all employees

相关标签:
2条回答
  • 2021-01-17 00:08

    Aggregations on repository methods do not support the Page return type. Please have a look at the Reference Documentation for supported return types (eg. List).

    I created DATAMONGO-2506 to improve the error message in that case.

    0 讨论(0)
  • 2021-01-17 00:11

    At least I was able to get the data with below query, but still struggling to make the data in the form of Pages

    db.country.aggregate([
      {
        $group: {
          _id: "$departments.deptCd", matches: { $push: '$$ROOT' }
        },
        $facet: {}
      }
    ])
    

    Reference from : Keeping field in mongodb group by and how to group in mongoDB and return all fields in result

    0 讨论(0)
提交回复
热议问题