TypeError:无法在result.toArray读取未定义\ n的属性'n'

时间:2018-07-04 08:53:26

标签: mongodb mongoose node-mongodb-native mongodb4.0

我正在从mongodb 3.6升级到mongodb 4.0,并对聚合(似乎)有问题。

我遇到了这个错误:

  

TypeError:无法读取未定义的属性'n'\ n   result.toArray   (/eliot-local-git/node_modules/mongodb/lib/operations/collection_ops.js:237:46)\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在   complete关闭   (/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

enter image description here


我也尝试过使用游标,但是它没有用:

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

@Alex Blex here是我看到的与mongodb-native-driver 3.1兼容的地方

enter image description here

1 个答案:

答案 0 :(得分:1)