mongoose icon indicating copy to clipboard operation
mongoose copied to clipboard

MongoDB error when adding the async cursor option to aggregate query

Open ghost opened this issue 10 years ago • 16 comments

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

ghost avatar Apr 27 '16 14:04 ghost

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" }"

id-ekaagr avatar Dec 15 '17 02:12 id-ekaagr

This issue re-surfaced when we've migrated to MongoDB 3.6

rturk avatar Dec 19 '17 17:12 rturk

@rturk @bestphoneappsdev code samples please?

vkarpov15 avatar Dec 27 '17 16:12 vkarpov15

same problem here.. when i update to mongo v 3.6

nuwanarti avatar Dec 27 '17 22:12 nuwanarti

same here, my code:

App.aggregate([
    {
        $match: {
            .. 
        }
    },
    {
        $unwind: '$team'
    },
    ....
], ( err, result ) => {
    console.log( err, result );
})

using mongodb 3.6 mongoose 4.11

kumangxxx avatar Dec 28 '17 04:12 kumangxxx

I get alike error on PHP after upgrading to mongodb 3.6 (from 3.4)

edohay avatar Dec 29 '17 16:12 edohay

@vkarpov15 fixed after I've upgraded to the latest Mongoose version

rturk avatar Dec 29 '17 16:12 rturk

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

rturk avatar Dec 29 '17 16:12 rturk

@rturk what version of mongoose did you upgrade to? 4.13.8 or 5.0.0-rc0?

vkarpov15 avatar Dec 30 '17 20:12 vkarpov15

@vkarpov15 4.13.7

rturk avatar Dec 31 '17 18:12 rturk

@rturk can we close this one out then?

sobafuchs avatar Jan 06 '18 19:01 sobafuchs

@varunjayaraman for my case yes.

rturk avatar Jan 06 '18 22:01 rturk

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.

samcraigjohnson avatar Apr 04 '18 18:04 samcraigjohnson

@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.

vkarpov15 avatar Apr 11 '18 17:04 vkarpov15

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.

jasleen19 avatar Jun 15 '18 06:06 jasleen19

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" } ] }

jasleen19 avatar Jun 15 '18 06:06 jasleen19