Use of the aggregate command without the 'cursor' option is deprecated

Viewed 272

I'm using mongoose to call an aggregate command on a model.

User.aggregate({
        $match: {
            timezone: {
                $in: timezones
            }
        }
    }, {
        $group: {
            _id: '$timezone',
            "count": {
                $sum: 1
            }
        }
    })

    .exec(function (err, data) {

    if (err != null) {
            console.log("Error: " + err);
            return;
        }

        // do stuff with data
    });

But mongo always complains

Use of the aggregate command without the 'cursor' option is deprecated.

1 Answers

I have faced similar kind of problem and after researching a lot I found that that it was due to older version of mongoose as earlier versions are not compatible with breaking changes in MongoDB 3.6 and above.

I upgraded mongoose version one by one and I found that it works perfectly fine with mongoose version 4.12.2 or above (mongoose@4.12.2).

You can upgrade your mongoose version by running following command:

npm install mongoose@4.12.2
Related