Closed gianpaj closed 5 years ago
Got it, thanks for the detailed bug report!
any fix for this issue? experiencing the same problem with latest stable 3.6.x mongodb and latest mongo-hacker
I have the same problem:
This is my query
db.contracts.aggregate([{ $lookup: { from: 'machines', localField: '_id', foreignField: 'contract_id', as: 'machine' } }, { $unwind: { path: '$machine', preserveNullAndEmptyArrays: true } }, { $lookup: { from: 'contract_elements', localField: 'machine._id', foreignField: 'machine_id', as: 'contract_element' } }, { $unwind: { path: '$contract_element', preserveNullAndEmptyArrays: true } } ]).pretty()
Without this package it works correctly. When I installed package and typed mongo
I saw
MongoDB server version: 3.6.4
Mongo-Hacker 0.0.14
And the same query caused error:
printStackTrace@src/mongo/shell/utils.js:74:15
DBCollection.prototype.aggregate@/home/daniel/.mongorc.js:551:13
@(shell):1:1
2018-04-18T06:33:32.119+0200 E QUERY [thread1] uncaught exception: aggregate failed: {
"ok": 0,
"errmsg": "The 'cursor' option is required, except for aggregate with the explain argument",
"code": 9,
"codeName": "FailedToParse"
}
I am using Ubuntu and version of mongo from his repository.
mongo --version
MongoDB shell version v3.6.4
git version: d0181a711f7e7f39e60b5aeb1dc7097bf6ae5856
OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
allocator: tcmalloc
modules: none
build environment:
distmod: ubuntu1604
distarch: x86_64
target_arch: x86_64
Further searching:
db.contracts.find({})
Works correctly but
db.contracts.aggregate([])
finish with error:
printStackTrace@src/mongo/shell/utils.js:74:15
Aggregation.prototype.execute@/home/daniel/.mongorc.js:605:9
Aggregation.prototype.shellPrint@/home/daniel/.mongorc.js:623:9
shellPrintHelper@src/mongo/shell/utils.js:549:1
@(shell2):1:1
2018-04-18T06:41:32.746+0200 E QUERY [thread1] uncaught exception: aggregation failed: {
"ok": 0,
"errmsg": "The 'cursor' option is required, except for aggregate with the explain argument",
"code": 9,
"codeName": "FailedToParse"
}
@gustawdaniel Hi! Any news about cursor error? My prod app crashed :(
@kayoshi @JimmyLonely Can you clarify what you mean by "prod app crashed"? mongo-hacker
is an extension for the mongo
shell and should not affect your MongoDB server. The errors reported earlier in this issue are client errors.
If you suspect compatibility problems with mongo-hacker
, try starting your shell with mongo --norc
to ignore any extensions.
@gianpaj Hye I am using MongoDb: 3.6.6 and mongoose 4.7.2, I getting same issue, If I use
cursor({ batchSize: 1000 })
it's going to resolve and reject part.
@AKArunkumar I'm not sure where you can define the cursor's batch size.
I made an initial PR to fix one part of this: https://github.com/TylerBrock/mongo-hacker/pull/191
Instead of using:
db.collection.runCommand("aggregate", cmd);
I'm using:
var cmdObj = db.collection._makeCommand("aggregate", cmd);
return db.collection._db._runAggregate(cmdObj, extraOpts);
BTW I'm not sure if those functions are compatible with all version of the server and/or client.
In my foolishness I thought this was a MongoDB bug.
I think there's an easier fix, I've simply added a few lines after: https://github.com/TylerBrock/mongo-hacker/blob/f15ce3ffc9164be1b7d825e219c85fd2c8936420/hacks/aggregation.js#L17-L19
So it now looks like:
if (extraOpts === undefined) {
extraOpts = {};
}
if (extraOpts.cursor === undefined){
extraOpts.cursor = {batchSize: 1000};
}
var cmd = {pipeline: arr};
Object.extend(cmd, extraOpts);
@WoLpH awesome!
That's a much better bug fix!
Do you want to send PR? Otherwise I'm happy to
I've created a pull request :)
Issue also with
aggregate()
function without the array.same issue with mongo shell 3.4.3 btw
Looks like the issue is also(?) related to the server version