The field "$name" must be an accumulator object

the field book
the field (1990 full movie)
the field (2019)
the field irish pub
the field musician
the field irish pub events
the field apartments
the field netflix

I have a query and when I use a $group a error shows "the field "$name must be an accumulator object", if if remove the filed "$name" all works well and i have tried to use only "name" instead of "$name" and the error continues.

   User.aggregate([
    {
      $match: {
        "storeKey": req.body.store        
      }
  },
  {
      $group: {
          "_id": "$_id",          
          "name": "$name",              
          "count": {
              "$sum": 1
          },
          "totalValue": {
              "$sum": "$value"
          }      
      }
  },
  {
    $sort: sort
  },
  {
     $skip: req.body.limit * req.body.page
  },
  {
     $limit: req.body.limit
  }
])...

There are some aggregation operators that can only be used in $group aggregation and named as $group accumulators

Just as you used $sum here you have to use for the name key as well

{ "$group": {
  "_id": "$_id",
  "name": { "$first": "$name" },  //$first accumulator
  "count": { "$sum": 1 },  //$sum accumulator
  "totalValue": { "$sum": "$value" }  //$sum accumulator
}}

Accumulator is like array of Elements its Accumulates as Array. $first -> gives 1st name that goes in the group of names

Example: so if you have $_id same but different name ["Darik","John"] specifying $first will give Darik & similarly $last will give John

Line of Descent (2019 film), Directed by Tate Bunker. With Tim Higgins, Veronica Cartwright, Barry Bostwick, Mark Metcalf. A long-empty farmstead holds secret worlds, accidentally  Directed by Tate Bunker. With Tim Higgins, Veronica Cartwright, Barry Bostwick, Mark Metcalf. A long-empty farmstead holds secret worlds, accidentally unlocked by an amateur photographer and his wife.


db.faq_feedback.aggregate({ 
   $lookup:{ 
      "from":"faq",
      "localField":"question_id",
      "foreignField":"_id",
      "as":"faq"
   }
},
{ 
   $unwind:"$faq"
},

{ 
   $project:{ 
      "question_id":1,
      "lang":"$faq.lang",
      "feedback":"$faq.feedback",
      "question":"$faq.question",
      "yes":{ 
         "$cond":[ 
            { 
               "$eq":[ 
                  "$feedback",
                  "yes"
               ]
            },
            1,
            0
         ]
      },
      "no":{ 
         "$cond":[ 
            { 
               "$eq":[ 
                  "$feedback",
                  "no"
               ]
            },
            1,
            0
         ]
      }
   }
},

{ 
   $group:{ 
      "_id":"$question_id",

      "yes":{ 
         "$sum":"$yes"
      },
      "no":{ 
         "$sum":"$no"
      },
      "question":{"$first":"$question"},
      "lang":{"$first":"$lang"}
   }
},
{ 
   $limit:10000
},
{ 
   $skip:0
})

The Field Irish Pub, Directed by Jim Sheridan. With Richard Harris, John Hurt, Sean Bean, Frances Tomelty. When a field (which has been farmed by the McCabe family for  "The Field" is generally regarded as Keane's greatest achievement. He was certainly aware of that fact and had denied it to The Southern Theatre Company (STC), who had opened all, or most, of his other works. But "The Field" was not "Many Young Girls of Twenty" and, for Keane, there was only one "Bull McCabe" - Ray McAnally.


$group: {
    _id:"$_id", 
    "name" :{ $last: '$name' }, 
    "count" : { $sum: 1 }, 
    "totalValue": { "$sum": "$value" }
}

The Field (film), The Field enables thousands of media and performing artists in NYC and beyond to thrive through creative programs, professional development workshops, and  The Field is a highly readable scientific detective story presenting a stunning picture of an interconnected universe and a new scientific theory that makes sense of supernatural phenomena. Documented by distinguished sources, The Field is a book of hope and inspiration for today's world.


The Field Irish Pub & Eatery, The Field. Born in southern Sweden, Axel Willner spent his formative years living in Stockholm and Lisbon, studying both at a formal music academy and in the  The Field enables thousands of media and performing artists in NYC and beyond to thrive through creative programs, professional development workshops, and consultations.


The Field (2019), The Field is a highly readable scientific detective story presenting a stunning picture of an interconnected universe and a new scientific theory that makes sense of supernatural phenomena.


The Field (1990), The Field: The Quest for the Secret Force of the Universe seemed promising and interesting to me at first glance because of author Lynne McTaggart ’s angle.