Home > Software design >  A pipeline stage specification object must contain exactly one field
A pipeline stage specification object must contain exactly one field

Time:03-22

db.P2447653_reviews_c.aggregate([{ $group: {_id: {"reviewerID" : "reviewerID", count: {$sum: 1 }}}, $match:{"reviewTime":{$gt:1}}, $project : { "reviewerID":1, "reviewerName":1, "reviewTime":1}} ])

I don't understand the problem, I'm very new to MongoDB

Error: MongoServerError: A pipeline stage specification object must contain exactly one field.

I have no idea what else to try. I'm completely stuck.

CodePudding user response:

Doing some formatting, your query is this:

db.P2447653_reviews_c.aggregate([
   {
      $group: { _id: { "reviewerID": "reviewerID", count: { $sum: 1 } } },
      $match: { "reviewTime": { $gt: 1 } },
      $project: { "reviewerID": 1, "reviewerName": 1, "reviewTime": 1 }
   }
])

You missed some brackets, must be this:

db.P2447653_reviews_c.aggregate([
   {
      $group: {
         _id: { "reviewerID": "$reviewerID" },
         count: { $sum: 1 }
      }
   },
   { $match: { "reviewTime": { $gt: 1 } } },
   { $project: { "reviewerID": 1, "reviewerName": 1, "reviewTime": 1 } }
])
  • Related