Compound group id in the Java Driver using Aggregates.group

256 views
Skip to first unread message

Eric Fialkowski

unread,
May 16, 2016, 7:09:14 PM5/16/16
to mongodb-user
I'm trying to convert a $group pipeline option to use the Aggregates.group functionality. I can't figure out how to construct a compound grouping id.

Here is the $group step:
{$group: {_id: {aid: "$account_id", etl: "$etl_type"},max_mem: { $max: "$final_metrics.memory.max" }}},

Here is where I'm stuck:
group(<what goes here?>,max("max_mem","$final_metrics.memory.max"))

Single fields work fine, I can't figure out what to put to make multiple fields work.

Jeff Yemin

unread,
May 17, 2016, 9:00:28 AM5/17/16
to mongodb-user
Try something like this:

group(new Document("aid", "$accound_id").append("etl", "$etl_type"),
        max("max_mem","$final_metrics.memory.max"));


Regards,
Jeff

Eric Fialkowski

unread,
May 17, 2016, 9:47:35 AM5/17/16
to mongodb-user
Thanks, that worked. I was overthinking it and was trying to use something like fields(...) 
Reply all
Reply to author
Forward
0 new messages