How to replace $$ROOT for group in AWS DocumentDB - Feature not supported: $$ROOT

Viewed 791

I have a Node app interacting with a Mongo database. When running on the old setup or locally on MongoDB 4.4.0

When I deploy to AWS Document DB 3.6.0 and try to run a query with the below $group clause, I get an error that Feature not supported: $$ROOT

  {
    $group: {
      "_id": "$user_id",
      "total_paid_amount": {
        $sum: "$amount"
      },
      "data": {
        $push: "$$ROOT"
      }
    }
  }

According to this doc https://docs.aws.amazon.com/documentdb/latest/developerguide/developerguide.pdf, $$ROOT is not supported in DocumentDB

How can I work around this issue, or perform the same query without pushing $$ROOT?

Thanks in advance!

2 Answers

Ended up just having to push the items I actually needed/wanted instead of all via $$ROOT

$push: {
  fieldOne: "$fieldOne",
  fieldTwo: "$fieldTwo"
}

Support for $$ROOT was added to Amazon DocumentDb in October 2021.

Related