mongo scala aggregation renaming group _od

11 views
Skip to first unread message

Colin Bester

unread,
Feb 14, 2018, 11:36:33 AM2/14/18
to mongodb-user
Presently I am using group pipeline with mongo scala driver

group("$status",
 sum
("unread", "$numunread"),
 sum
("tickets", 1))
))

which results in output of {_id:statusField, unread: .., tickets: ...}

Is there a way to set name of group id to something else besides _id?

Wan Bachtiar

unread,
Feb 28, 2018, 1:57:55 AM2/28/18
to mongodb-user

Is there a way to set name of group id to something else besides _id?

Hi Colin,

The _id field is part of $group expression and it’s mandatory.
However, you can append a $project stage into the pipeline to rename the _id field.

See also MongoDB Scala Driver 2.2: Aggregate project()

Regards,
Wan.

Reply all
Reply to author
Forward
0 new messages