Skip to Main Content

MongoByte MongoDB Logo

Welcome to the new MongoDB Feedback Portal!

{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.

Status Submitted
Categories Database
Created by Guest
Created on Aug 2, 2023

$group all fields

$group should have the ability to allow specifying all fields in a document (without explicitly defining them all, which can lead to duplicating dozens of lines just to do "key: $first") This will help users that use $unwind and then want to $group the results without having to do a subsequent $lookup and $mergeObjects (or similar) to get the final document structure they're looking for.
  • Attach files
  • Guest
    Oct 25, 2023
    Would using $$ROOT like this work: {$group: {_id: '$groupkey', document: {$first: '$$ROOT'}}} ? If not, could you provide an example of the document and the pipeline that achieves the transformation (with the stages you mentioned). thank you