TypeError: Cannot read property 'n' of undefined\n at result.toArray

TypeError: Cannot read property 'n' of undefined\n at result.toArray

我正在从 mongodb 3.6 升级到 mongodb 4.0 并且聚合有问题 (看起来)

我遇到了这个错误:

TypeError: Cannot read property 'n' of undefined\n at result.toArray (/eliot-local-git/node_modules/mongodb/lib/operations/collection_ops.js:237:46)\n at result (/eliot-local-git/node_modules/mongodb/lib/utils.js:414:17)\n at executeCallback (/eliot-local-git/node_modules/mongodb/lib/utils.js:406:9)\n at handleCallback (/eliot-local-git/node_modules/mongodb/lib/utils.js:128:55)\n at cursor.close (/eliot-local-git/node_modules/mongodb/lib/operations/cursor_ops.js:218:62)\n at handleCallback (/eliot-local-git/node_modules/mongodb/lib/utils.js:128:55)\n at completeClose (/eliot-local-git/node_modules/mongodb/lib/cursor.js:887:14)\n at _endSession (/eliot-local-git/node_modules/mongodb/lib/cursor.js:898:37)\n at AggregationCursor.Cursor._endSession (/eliot-local-git/node_modules/mongodb/node_modules/mongodb-core/lib/cursor.js:193:5)\n at AggregationCursor.Cursor._endSession (/eliot-local-git/node_modules/mongodb/lib/cursor.js:226:59)\n at AggregationCursor.Cursor.close (/eliot-local-git/node_modules/mongodb/lib/cursor.js:898:19)\n at cursor._next (/eliot-local-git/node_modules/mongodb/lib/operations/cursor_ops.js:218:23)\n at handleCallback (/eliot-local-git/node_modules/mongodb/node_modules/mongodb-core/lib/cursor.js:202:5)\n at _setCursorNotifiedImpl (/eliot-local-git/node_modules/mongodb/node_modules/mongodb-core/lib/cursor.js:560:38)\n at self._endSession (/eliot-local-git/node_modules/mongodb/node_modules/mongodb-core/lib/cursor.js:568:46)\n at AggregationCursor.Cursor._endSession (/eliot-local-git/node_modules/mongodb/node_modules/mongodb-core/lib/cursor.js:193:5)


我的聚合调用如下:

collectionSchema.aggregate(query).exec();

使用:

mongodb v4.0.0


我也试过使用游标,但没用:

collectionSchema.aggregate(query)
        .cursor({
          batchSize: 10
        })
        .exec();

@Alex Blex here 是我看到与 mongodb-native-driver 3.1

的兼容性的地方

有一个错误https://jira.mongodb.org/browse/NODE-1543, fixed in v3.1.1 14 hrs ago: https://github.com/mongodb/node-mongodb-native/commit/09c7d8e4ce302f1c8f6339dd19ee4b86e40b30a8