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

前端 未结 2 1736
逝去的感伤
逝去的感伤 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: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

提交回复
热议问题