MongoDB 版本由 4.2 升级至 5.0,某处查询语句执行后报:
MongoError: Path collision at activity_detail.period.start_date remaining portion period.start_date
at MessageStream.messageHandler (/usr/src/app/node_modules/mongodb/lib/cmap/connection.js:261:20)
at MessageStream.emit (events.js:400:28)
at processIncomingData (/usr/src/app/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
at MessageStream._write (/usr/src/app/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
at writeOrBuffer (internal/streams/writable.js:358:12)
at MessageStream.Writable.write (internal/streams/writable.js:303:10)
at Socket.ondata (internal/streams/readable.js:731:22)
at Socket.emit (events.js:400:28)
at addChunk (internal/streams/readable.js:293:12)
at readableAddChunk (internal/streams/readable.js:267:9)
at Socket.Readable.push (internal/streams/readable.js:206:10)
at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
at TCP.callbackTrampoline (internal/async_hooks.js:130:17)
执行代码大致如下:文章来源:https://www.toymoban.com/news/detail-486163.html
const activityUserFields: string[] = [
'activity_detail.period',
'activity_detail.period.start_date',
'activity_detail.period.end_date',
];
const activityUser: ActivityUserEntity = await ctx.service.activity.activityUser.queryActivityUser({
user_id: user._id,
}, activityUserFields);
原因:文章来源地址https://www.toymoban.com/news/detail-486163.html
- MongoDB 4.4 版本之后更新了路径映射算法,不允许在投影操作中同时投影嵌套文档和嵌套文档的字段,否则会导致路径冲突错误,报 Path collision 错误。上述代码中去除 activity_detail.period.start_date 和 activity_detail.period.end_date 即可。
- 官方 Q&A
到了这里,关于MongoDB 运行报 code: 31249, MongoError: Path collision at...的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!