Mongodb 收到错误消息“MongoError:活动中的路径冲突" [英] Mongodb get error message "MongoError: Path collision at activity"

查看:39
本文介绍了Mongodb 收到错误消息“MongoError:活动中的路径冲突"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 node.js 项目中为 mongodb 使用 mongoose 库.在我的日志文件中收到 mongodb 错误消息:

I am using mongoose library for the mongodb on my node.js project. On of my logs file getting the mongodb error message:

{
  message: 'Path collision at activity',
  stack: 'MongoError: Path collision at activity
' +
    '    at Connection.<anonymous> (/project/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:443:61)
' +
    '    at Connection.emit (events.js:315:20)
' +
    '    at Connection.EventEmitter.emit (domain.js:483:12)
' +
    '    at processMessage (/project/node_modules/mongoose/node_modules/mongodb-core/lib/connection/connection.js:364:10)
' +
    '    at Socket.<anonymous> (/project/node_modules/mongoose/node_modules/mongodb-core/lib/connection/connection.js:533:15)
' +
    '    at Socket.emit (events.js:315:20)
' +
    '    at Socket.EventEmitter.emit (domain.js:483:12)
' +
    '    at addChunk (_stream_readable.js:295:12)
' +
    '    at readableAddChunk (_stream_readable.js:271:9)
' +
    '    at Socket.Readable.push (_stream_readable.js:212:10)
' +
    '    at TCP.onStreamRead (internal/stream_base_commons.js:186:23)',
  operationTime: Timestamp { _bsontype: 'Timestamp', low_: 2, high_: 1600849377 },
  ok: 0,
  errmsg: 'Path collision at activity',
  code: 31250,
  codeName: 'Location31250',
  '$clusterTime': {
    clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 2, high_: 1600849377 },
    signature: {
      hash: Binary {
        _bsontype: 'Binary',
        sub_type: 0,
        position: 20,
        buffer: <Buffer d2 34 b7 ac bc a7 3f ea 38 d1 5c e3 26 58 39 43 d8 11 6c 83>
      },
      keyId: Long { _bsontype: 'Long', low_: 4, high_: 1596659428 }
    }
  },
  name: 'MongoError',
  level: 'info',
  timestamp: '2020-09-23 08:22:57',
  [Symbol(mongoErrorContextSymbol)]: {}
}

这个错误没有指出哪个函数返回这个错误的错误位置.如果有人有任何线索,请告诉我.提前致谢.

This error did not point the location of error that on which function return this error. If anyone have anyclue then kindly let me know. Thanks in advance.

推荐答案

问题应该出在投影上.自 v4.4 以来,此错误是作为重大更改的一部分引入的.

The problem should rely in the projection. This error is introduced as part of breaking change since v4.4.

来自 此处的 MongoDB 4.4 发行说明:

从 MongoDB 4.4 开始,使用任何嵌入文档的字段投影嵌入文档是非法的.

Path Collision: Embedded Documents and Its Fields

Starting in MongoDB 4.4, it is illegal to project an embedded document with any of the embedded document’s fields.

例如,考虑一个包含 size 字段的文档的集合清单:

For example, consider a collection inventory with documents that contain a size field:

{ ..., size: { h: 10, w: 15.25, uom: "cm" }, ... }

从 MongoDB 4.4 开始,以下操作失败并出现路径冲突错误,因为它尝试同时投影大小文档和 size.uom 字段:

Starting in MongoDB 4.4, the following operation fails with a Path collision error because it attempts to project both size document and the size.uom field:

db.inventory.find( {}, { size: 1, "size.uom": 1 } )  // Invalid starting in 4.4

在以前的版本中,嵌入文档及其字段之间的最后一个投影决定了投影:

In previous versions, lattermost projection between the embedded documents and its fields determines the projection:

  • 如果嵌入文档的投影在其字段的任何和所有投影之后,MongoDB 将投影嵌入文档.例如,投影文档 { "size.uom": 1, size: 1 } 产生与投影文档 { size: 1 } 相同的结果.
  • 如果嵌入文档的投影在其任何字段的投影之前,MongoDB 将投影指定的一个或多个字段.例如,投影文档 { "size.uom": 1, size: 1, "size.h": 1 } 产生与投影文档 { ";size.uom": 1, "size.h": 1 }
  • If the projection of the embedded document comes after any and all projections of its fields, MongoDB projects the embedded document. For example, the projection document { "size.uom": 1, size: 1 } produces the same result as the projection document { size: 1 }.
  • If the projection of the embedded document comes before the projection any of its fields, MongoDB projects the specified field or fields. For example, the projection document { "size.uom": 1, size: 1, "size.h": 1 } produces the same result as the projection document { "size.uom": 1, "size.h": 1 }

这篇关于Mongodb 收到错误消息“MongoError:活动中的路径冲突"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆