Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDB error when adding the async cursor option to aggregate query #4101

Closed
ghost opened this issue Apr 27, 2016 · 16 comments
Closed

MongoDB error when adding the async cursor option to aggregate query #4101

ghost opened this issue Apr 27, 2016 · 16 comments
Labels
needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue

Comments

@ghost
Copy link

ghost commented Apr 27, 2016

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
@vkarpov15 vkarpov15 added this to the 4.4.15 milestone Apr 28, 2016
vkarpov15 added a commit that referenced this issue Apr 29, 2016
@id-ekaagr
Copy link

id-ekaagr commented 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" }"

@rturk
Copy link

rturk commented Dec 19, 2017

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

@vkarpov15
Copy link
Collaborator

@rturk @bestphoneappsdev code samples please?

@nuwanarti
Copy link

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

@kumangxxx
Copy link

same here, my code:

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

using mongodb 3.6
mongoose 4.11

@vkarpov15 vkarpov15 reopened this Dec 28, 2017
@vkarpov15 vkarpov15 modified the milestones: 4.4.15, 4.13.9 Dec 28, 2017
@vkarpov15 vkarpov15 added needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue and removed priority labels Dec 28, 2017
@edohay
Copy link

edohay commented Dec 29, 2017

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

@rturk
Copy link

rturk commented Dec 29, 2017

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

@rturk
Copy link

rturk commented Dec 29, 2017

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

@vkarpov15
Copy link
Collaborator

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

@rturk
Copy link

rturk commented Dec 31, 2017

@vkarpov15 4.13.7

@sobafuchs
Copy link
Contributor

@rturk can we close this one out then?

@rturk
Copy link

rturk commented Jan 6, 2018

@varunjayaraman for my case yes.

@samcraigjohnson
Copy link

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.

@vkarpov15
Copy link
Collaborator

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

tpaz added a commit to tpaz/Node-DC-EIS that referenced this issue Apr 25, 2018
Turns out with latest Mongo DB, nodejs fails when client load is triggered. 
The symptom: 
  client fails load with following error: Fatal error-No more IDs available. Aborting
Root cause:
  Node server fails with following error:

```{ MongoError: The 'cursor' option is required, except for aggregate with the explain argument
    at Function.MongoError.create (/home/nodeuser/Node-DC-EIS-cluster/node_modules/mongodb-core/lib/error.js:31:11)
    at commandCallback (/home/nodeuser/Node-DC-EIS-cluster/node_modules/mongodb-core/lib/topologies/server.js:1154:66)
    at Callbacks.emit (/home/nodeuser/Node-DC-EIS-cluster/node_modules/mongodb-core/lib/topologies/server.js:119:3)
    at Connection.messageHandler (/home/nodeuser/Node-DC-EIS-cluster/node_modules/mongodb-core/lib/topologies/server.js:295:23)
    at Socket.<anonymous> (/home/nodeuser/Node-DC-EIS-cluster/node_modules/mongodb-core/lib/connection/connection.js:285:22)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:547:20)
  name: 'MongoError',
  message: 'The \'cursor\' option is required, except for aggregate with the explain argument',
  ok: 0,
  errmsg: 'The \'cursor\' option is required, except for aggregate with the explain argument',
  code: 9,
  codeName: 'FailedToParse' }```

this is described in Mongoose issue: Automattic/mongoose#4101

Solution: update to latest of that release (4.12.13) - problem is gone, no Node errors and client load runs smooth.
@jasleen19
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro script Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue
Projects
None yet
Development

No branches or pull requests

10 participants