Skip to content

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

Open
@spring-projects-issues

Description

@spring-projects-issues

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)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions