question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MongoDB error when adding the async cursor option to aggregate query

See original GitHub issue

When adding the async cursor option I get the following error:

MongoError: cursor object can't contain fields other than batchSize

The (simplified) query:

var pipeline = [
    { $lookup: {
        from: "interactions",
        localField: "_id",
        foreignField: "message_id",
        as: "interactions"
    }},
    { $project: {
        id: "$_id",
        numberOfInteractions: { $size: "$interactions" }
    }},
    { $match: {
        numberOfInteractions: { $eq: 0 }
    }}
];

var promise = Message
    .aggregate(pipeline)
    .allowDiskUse(true)
    .cursor({ batchSize: 2500, async: true })
    .exec();

If I make this modification the error goes away:

diff --git a/lib/aggregate.js b/lib/aggregate.js
index fd2c2fc..ad76bd6 100644
--- a/lib/aggregate.js
+++ b/lib/aggregate.js
@@ -499,6 +499,7 @@ Aggregate.prototype.exec = function(callback) {

   if (this.options && this.options.cursor) {
     if (this.options.cursor.async) {
+      delete this.options.cursor.async;
       return new Promise.ES6(function(resolve) {
         if (!_this._model.collection.buffer) {
           process.nextTick(function() {

My setup:

NodeJS 4.2.4
MongoDB version 3.2.5
Mongoose 4.4.13

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:16 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
company-locommented, Dec 15, 2017

This issue is still coming while using MongoDB 3.6 on server.

I get the following error when asking questions :

“Command failed with error 9: ‘The ‘cursor’ option is required, except for aggregate with the explain argument’ on server 127.0.0.1:28001. The full response is { “ok” : 0.0, “errmsg” : “The ‘cursor’ option is required, except for aggregate with the explain argument”, “code” : 9, “codeName” : “FailedToParse” }”

2reactions
rturkcommented, Dec 29, 2017

@raoulwissink looks like its fixed in the newer versions of Mongoose

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mongodb error : The 'cursor' option is required, except for ...
You need to provide cursor option for aggregate calls which is changed in Mongo 3.6.
Read more >
Lab 4.2 Aggregation Performance - M201 - MongoDB
I am currently on Lab 4.2 and I am getting a different error than what ... "errmsg": "The 'cursor' option is required, except...
Read more >
MotorCursor — Motor 3.1.1 documentation
Adds a 'hint', telling Mongo the proper index to use for the query. ... Use async for to elegantly iterate over MotorCursor objects...
Read more >
AggregationCursor - Mongoose v5.13.15:
Unless you're an advanced user, do not instantiate this class directly. Use Aggregate#cursor() instead. AggregationCursor.prototype.Symbol.asyncIterator().
Read more >
[CSHARP-2374] Aggregate Option Comment gives an error ...
What version of the MongoDB server are you testing with? The documentation points out that comment support for aggregation was added in MongoDB ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found