I am using latest version of mongodb 3.6 even after getting following error...

MongoError: The 'cursor' option is required, except for aggregate with the explain argument

const user = await User.aggregate([
      { $group: {
          _id: '$_id',
          domain: { $push: "$domain" },
          domain: { $push: "$email" },
          domain: { $push: "$userName" }
        }
      }
    ])

Solution 1

Thanks @Neil Lunn

Update mongoose. Mongoose versions prior to 5.0 are incorrectly matched for MongoDB 3.6. MongoDB 3.6 changed the aggregate API from "cursor optional" to "cursor only", and older mongoose versions break this by trying to invoke a deprecated way to ask for an array in response.