我正在从mongodb 3.6
to升级mongodb 4.0
并遇到聚合问题(似乎)。
我有这个错误:
类型错误:无法在 result.toArray (/eliot-local-git/node_modules/mongodb/lib/operations/collection_ops.js:237:46) 处读取未定义的属性 'n'\n 结果 (/eliot-local- git/node_modules/mongodb/lib/utils.js:414:17)\n 在 executeCallback (/eliot-local-git/node_modules/mongodb/lib/utils.js:406:9)\n 在 handleCallback (/eliot- local-git/node_modules/mongodb/lib/utils.js:128:55)\n 在 cursor.close (/eliot-local-git/node_modules/mongodb/lib/operations/cursor_ops.js:218:62)\n在 handleCallback (/eliot-local-git/node_modules/mongodb/lib/utils.js:128:55)\n 在 completeClose (/eliot-local-git/node_modules/mongodb/lib/cursor.js:887:14) \n 在 _endSession (/eliot-local-git/node_modules/mongodb/lib/cursor.js:898:37)\n 在 AggregationCursor.Cursor。_endSession (/eliot-local-git/node_modules/mongodb/node_modules/mongodb-core/lib/cursor.js:193:5)\n 在 AggregationCursor.Cursor._endSession (/eliot-local-git/node_modules/mongodb/lib /cursor.js:226:59)\n 在 AggregationCursor.Cursor.close (/eliot-local-git/node_modules/mongodb/lib/cursor.js:898:19)\n 在 cursor._next (/eliot-local -git/node_modules/mongodb/lib/operations/cursor_ops.js:218:23)\n 在handleCallback (/eliot-local-git/node_modules/mongodb/node_modules/mongodb-core/lib/cursor.js:202:5 )\n 在 _setCursorNotifiedImpl (/eliot-local-git/node_modules/mongodb/node_modules/mongodb-core/lib/cursor.js:560:38)\n 在 self._endSession (/eliot-local-git/node_modules/mongodb /node_modules/mongodb-core/lib/cursor.js:568:46)\n 在 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在这里我看到了兼容性mongodb-native-driver 3.1