5

I tried to follow this How to use dot in field name?. But it result as the picture. There is a additional space:-

enter image description here

  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; nested exception is java.lang.IllegalArgumentException: Invalid BSON field name 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]. Please suggest me?

Community
  • 1
  • 1
masiboo
  • 4,537
  • 9
  • 75
  • 136

2 Answers2

7

In MongoDB field names cannot contain the dot (.) character as it is part of dot-notation syntax, see the documentation.

What third party API are you using ? Are you sure you need a dot ? Dots are commonly used when parsing JSON and your third party API should not need it.

Paul
  • 19,704
  • 14
  • 78
  • 96
Alex
  • 21,273
  • 10
  • 61
  • 73
2

So, a third party api is both constructing the keys (with periods in them), AND saving that to MongoDB?

I suggest that you open a bug ticker in said API:s tracker.

If this is not the case, encode the periods somewhere in the persistence code - and decode it on the way up.

folkol
  • 4,752
  • 22
  • 25