mongoose: MongoDB error when adding the async cursor option to aggregate query
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
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 16 (1 by maintainers)
Commits related to this issue
- test(aggregate): repro #4101 — committed to Automattic/mongoose by vkarpov15 8 years ago
- bump Mongoose version to latest of its legacy release Turns out with latest Mongo DB, nodejs fails when client load is triggered. The symptom: client fails load with following error: Fatal erro... — committed to tpaz/Node-DC-EIS by tpaz 6 years ago
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
@vkarpov15 fixed after I’ve upgraded to the latest Mongoose version