【问题标题】:TypeError: Cannot read property 'n' of undefined\n at result.toArrayTypeError:无法在 result.toArray 处读取 undefined\n 的属性“n”
【发布时间】:2018-12-12 15:42:48
【问题描述】:

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

我遇到了这个错误:

TypeError: 无法读取属性 'n' of undefined\n at 结果.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 在 执行回调 (/eliot-local-git/node_modules/mongodb/lib/utils.js:406:9)\n 在 处理回调 (/eliot-local-git/node_modules/mongodb/lib/utils.js:128:55)\n 在 游标关闭 (/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 在 完成关闭 (/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 here 是我看到与mongodb-native-driver 3.1 兼容的地方

【问题讨论】:

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


    【解决方案1】:

    【讨论】:

    • 太棒了。谢谢。作为修复,我现在只让count 而不是countDocument 并保留deprecation warning
    猜你喜欢
    • 2016-10-24
    • 1970-01-01
    • 2020-01-29
    • 2021-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-09
    相关资源
    最近更新 更多