Skip to content

Add possibility to use an expression as parameter _id for group operation [DATAMONGO-2611] #3466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
spring-projects-issues opened this issue Aug 17, 2020 · 0 comments
Assignees
Labels
in: aggregation-framework Aggregation framework support type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: aggregation-framework Aggregation framework support type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants