0

I am updating a website for a scavenger hunt built on NodeJS and MongoDB and i'm having issues with the scoreboard feature.

All my environment variables are identical on my local machine and the live site but when it is deployed I get the error

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

below is the aggregate I am using

module.exports.getScores = (callback) => {
  Team.aggregate([
    { $group: {
      _id: "$code",
      name: { $first: "$name"},
      total: { $sum: "$score"}
    }}
    ], 
    (err, results) => {
      if (err) {
        callback(err);
        console.error(err);
      } else {
        callback(null, results);
      }
    }

  );
} 

I've google the issue and all solutions i've found seem not to work which is why I am posting.

NodeJS Version:8.10.0

MongoDB Version: 3.6.12

  • This is likely due to differences between the version of Mongoose and the MongoDB driver being used on each environment. Can you check the versions of each using `npm ls`? – Adam Harrison Aug 28 '19 at 20:41
  • they are both ^4.8.6 they are using the same package.json and in there 4.8.6 is specified – Ari Dokmecian Aug 28 '19 at 20:52

1 Answers1

0

The error message is related to a change in MongoDB 3.6, wherein aggregations need to return a cursor (https://docs.mongodb.com/manual/release-notes/3.6-compatibility/#aggregate-command-and-results).

In this case, the error is being thrown because the version of Mongoose being used (4.8.6) is not listed as compatible with MongoDB 3.6; the compatibility pages say that you'll need to use a 5.x version of mongoose

See Neil Lunn's comments here for more information.

Adam Harrison
  • 3,323
  • 2
  • 17
  • 25