简体   繁体   English

Mongo数据库无效的BSON字段名称异常

[英]Mongo database Invalid BSON field name exception

I tried to follow this How to use dot in field name? 我试着按照这个如何在字段名称中使用点? . But it result as the picture. 但它的结果如同图片。 There is a additional space:- 还有一个空间: -

在此输入图像描述

  protected Document setNestedField(Document doc, FieldValue parentField, String nestedFieldName, Object value, boolean concatenate) {
            if (concatenate) {
                doc.put(parentField.getSystemName() + "." + nestedFieldName, value);
            }
            else {
                doc.put(nestedFieldName, value);
            }
            return doc;
        }

Exception:-Invalid BSON field name photographs.inner_fields; 例外: - 无效的BSON字段名称photographs.inner_fields; nested exception is java.lang.IllegalArgumentException: Invalid BSON field name photographs.inner_fields. 嵌套异常是java.lang.IllegalArgumentException:无效的BSON字段名称为photographs.inner_fields。

How can I use dot "." 我怎么能用点“。” in field name. 在字段名称中。 I have to use . 我必须使用。 as I'm using some 3rd party api and I have no option to replace to something else like [dot]. 因为我正在使用一些第三方api,我没有选择替换像[dot]这样的东西。 Please suggest me? 请建议我?

In MongoDB field names cannot contain the dot (.) character as it is part of dot-notation syntax, see the documentation . 在MongoDB中,字段名称不能包含点(。)字符,因为它是点符号语法的一部分,请参阅文档

What third party API are you using ? 您使用的是哪种第三方API? Are you sure you need a dot ? 你确定你需要一个点吗? Dots are commonly used when parsing JSON and your third party API should not need it. 解析JSON时通常使用点,而您的第三方API不需要它。

So, a third party api is both constructing the keys (with periods in them), AND saving that to MongoDB? 那么,第三方api是否构建了密钥(其中包含了句点),并将其保存到MongoDB中?

I suggest that you open a bug ticker in said API:s tracker. 我建议您在所述API:s跟踪器中打开一个错误报告器。

If this is not the case, encode the periods somewhere in the persistence code - and decode it on the way up. 如果不是这种情况,请在持久性代码中的某个位置对周期进行编码 - 并在上升过程中对其进行解码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM