Reputation: 1
How to store the following document in mongo, I'm getting below error while inserting .
Document :
{
"data": {
"http://test.abc.com/xyz/xyz/displayname": "my Name"
}
}
ERROR :
java.lang.IllegalArgumentException: Invalid BSON field name http://test.abc.com/xyz/xyz/displayname
at org.bson.AbstractBsonWriter.writeName(AbstractBsonWriter.java:494)
at org.bson.codecs.DocumentCodec.writeMap(DocumentCodec.java:188)
at org.bson.codecs.DocumentCodec.writeValue(DocumentCodec.java:172)
at org.bson.codecs.DocumentCodec.writeMap(DocumentCodec.java:189)
at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:131)
at org.bson.codecs.DocumentCodec.encode(DocumentCodec.java:45)
at org.bson.codecs.BsonDocumentWrapperCodec.encode(BsonDocumentWrapperCodec.java:63)
Upvotes: 0
Views: 154
Reputation: 22974
Field names cannot contain the null character.
Top-level field names cannot start with the dollar sign ($) character.
Otherwise, starting in MongoDB 3.6, the server permits storage of field names that contain dots (i.e. .) and dollar signs (i.e. $).
Rather, you can store two fields. One for URI and another for name.
Upvotes: 1