MongoDB Compass报错:Path collision at


问题描述
有些字段格式比较自由,以下图为例,contact字段是字典,在每条记录中,它包含的键可能不一样:
在这里插入图片描述
这种情况下,正常入库,直接从MongoDB Compass导出报错:
在这里插入图片描述
发现是contact字段出了问题。


原问题

Export Collection - Path Collision Error

The collection export function of Compass 1.26.0 is faulty. The reason
for this is a self-inflicted path collision error (see picture 1).
This error occurs when a certain object contains properties (/fields
and values) in some documents and is empty in others. For example, the
error currently pops up when trying to export the “listingsAndReviews”
collection of the airbnb sample record.

Compass 1.26.0的集合导出功能有缺陷。原因是自己造成的路径碰撞错误(见图1)。当某个对象在某些文档中包含属性(/字段和值) ,而在另一些文档中为空时,就会发生此错误。例如,当试图导出 airbnb 样本记录的“ listingsAndReviews”集合时,当前弹出的错误。

Should an object contain properties in some documents and none in others, the export function provides an export field for the object in general as well as a field for each object property. In the airbnb case it includes “review_scores” and “review_scores.review_scores_accuracy” etc. (see picture 2). Compass thereby does not comply with the mongoDB Path Collision Restrictions introduced in mongoDB 4.4 (https://docs.mongodb.com/manual/release-notes/4.4-compatibility/#path-collision-restrictions).

如果一个对象在某些文档中包含属性,而在其他文档中没有,则 export 函数通常为该对象提供一个导出字段,并为每个对象属性提供一个字段。在 airbnb 的案例中,它包括“ review _ scores”和“ review _ scores”。复习 _ 分数 _ 准确性”等(见图2)。因此,指南针不符合 mongoDB 4.4中引入的 mongoDB 路径冲突限制 https://docs.mongoDB.com/manual/release-notes/4.4-compatibility/#Path-Collision-Restrictions。


看到这里基本上清楚了,以我们的字段为例:

"contact": {
    "Angeboteinholen",
    "Terminanfragen":,
    "Chatstarten":,
    “Vorbestellung”
  }

contact下共出现过4个不同字段,每条记录可能只含有其中的一两条,乃至空字典。但在默认导出时,Compass要求每条记录都含这四个字段,报错由此而来。


问题修复

Furthermore, you can circumvent this issue by either unticking the
object field in the export settings window or by unticking all the
individual object properties. In the example above by either unticking
“review_scores” or all of review_scores’s properties listed in dot
notation. In both cases Compass exports all the data.

此外,您可以通过取消导出设置窗口中对象字段的选项或取消所有单个对象属性的选项来避免这个问题。在上面的例子中,可以通过取消勾选的“ review _ scores”,也可以通过点符号列出 review _ scores 的所有属性。在这两种情况下,Compass 导出所有的数据。


在这里插入图片描述
导出时不要勾选contact下的字段就可以了。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐