MongoDB error when adding the async cursor option to aggregate query
See original GitHub issueWhen 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:
- Created 7 years ago
- Reactions:1
- Comments:16 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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” }”
@raoulwissink looks like its fixed in the newer versions of Mongoose