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
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" }"
This issue re-surfaced when we've migrated to MongoDB 3.6
@rturk @bestphoneappsdev code samples please?
same problem here.. when i update to mongo v 3.6
same here, my code:
App.aggregate([
{
$match: {
..
}
},
{
$unwind: '$team'
},
....
], ( err, result ) => {
console.log( err, result );
})
using mongodb 3.6 mongoose 4.11
I get alike error on PHP after upgrading to mongodb 3.6 (from 3.4)
@vkarpov15 fixed after I've upgraded to the latest Mongoose version
@raoulwissink looks like its fixed in the newer versions of Mongoose
@rturk what version of mongoose did you upgrade to? 4.13.8 or 5.0.0-rc0?
@vkarpov15 4.13.7
@rturk can we close this one out then?
@varunjayaraman for my case yes.
Hello! I know this issue is closed, but I was wondering what the root cause was. I have run into the same problem, and upgrading fixed it, but I was hoping to know what the underlying issue was. I did not see a relevant commit attached to this issue.
@sjohnson540 can you show the code that's causing this issue? This issue shouldn't show up in newer versions of mongoose, the issue was that the async flag that mongoose used internally was getting down to the mongodb server.
We have upgraded mongodb to 3.6.3 and one of the aggregations return this error when called from UI. It was working fine with 3.4.1. I don't know how to resolve it. Please help.
Please find the code:
{
"type":"pipeline",
"uri":"fetchpreloadedData",
"stages":[
{
"$facet":{
"riskProfiles":[
{
"$unwind":"$service-enrichment.risk-assess-service.enrich-data.risk_details.riskProfiles"
},
{
"$group":{
"id":"riskProfiles",
"profileNames":{
"$addToSet":"$service-enrichment.risk-assess-service.enrich-data.risk_details.riskProfiles"
}
}
}
],
"arrivalPorts":[
{
"$match":{
"travelType":"DEP"
}
},
{
"$group":{
"id":"arrivalPorts",
"portNames":{
"$addToSet":"$flight.destination"
}
}
}
],
"departurePorts":[
{
"$match":{
"travelType":"ARR"
}
},
{
"$group":{
"id":"departurePorts",
"portNames":{
"$addToSet":"$flight.origin"
}
}
}
],
"carrierNames":[
{
"$match":{
"flight.carrier":{
"$exists":true,
"$ne":null
}
}
},
{
"$group":{
"id":"carrierNames",
"carrierNames":{
"$addToSet":"$flight.carrier"
}
}
}
],
"flightNumbers":[
{
"$match":{
"flight.flightNumber":{
"$exists":true,
"$ne":null
}
}
},
{
"$group":{
"id":"flightNumbers",
"flightNumbers":{
"$addToSet":"$flight.flightNumber"
}
}
}
],
"citizenshipCountriesList":[
{
"$match":{
"citizenshipCountry":{
"$exists":true
}
}
},
{
"$group":{
"id":"citizenshipCountries",
"CountriesList":{
"$addToSet":"$citizenshipCountry"
}
}
}
]
}
},
{
"_$out":"preloadData"
}
]
}