spring-projects / spring-projects/spring-data-mongodb
Add possibility to use an expression as parameter _id for group operation [DATAMONGO-2611]
Open
@christophstrobl is already working on this.
Since Dec 30, 2020.
in: aggregation-framework
type: enhancement
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 1.1k
- PR merge metrics
- No merged PRs in 30d
Description
Dmitry Bekrenev opened DATAMONGO-2611 and commented
An example we have next data:
{ "_id" : ObjectId("5f3a61e5145c553d7d463fb9"), "location" : [ 1, 2 ], "userId" : 1 }
{ "_id" : ObjectId("5f3a61eb145c553d7d463fba"), "location" : [ 3, 4 ], "userId" : 5 }
{ "_id" : ObjectId("5f3a61f2145c553d7d463fbb"), "location" : [ 6, 7 ], "userId" : 8 }
and next query:
{$group: {_id: {userId: "$userId", lat: {$arrayElemAt: ["$location", 1]}, lng: {$arrayElemAt: ["$location", 0]}}}}
Problem:
Looks like no way to implement the query by the Aggregation framework.
Expected behavior:
I expect that is will be possible to implement by next code:
val groupByUserIdAndLocation = Aggregation.group("userId")
.and(
ArrayOperators.arrayOf("location")
.elementAt(0)
).as("lng")
.and(ArrayOperators.arrayOf("location")
.elementAt(1)).as("lat")
Affects: 3.0.3 (Neumann SR3)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.