I want to put String "http://1.1.1.1/olala" into mongodb, but instead of
{data: "http://1.1.1.1/olala"}
I get
{data: {"http://1": {1: {1: "1/olala"}}}}
Is there a standard way to insert string with special characters into mongodb using java?
The way I'm doing the upsert is
collection.updateOne(new Document("name", key),
new Document("$inc", new Document(methodName, 1)),
opt.upsert(true), null);
where methodName
is url with commas. I tried to quote values, but instead got
{data: {"'http://1": {1: {1: "1/olala'"}}}}
And beside that, I suggest that there would be more "bad" characters later.
UPD more complex example, but don't understand how it will help
final UpdateOptions opt = new UpdateOptions();
final String methodName = "http://1.1.1.1/ololo";
final MongoCollection<Document> collection =
MongoAsyncClientFactory.getCollection();
//final String key = Statistics.getMainKey();
final String key = "any-key-you-want";
collection.updateOne(new Document("name", key),
new Document("$inc", new Document(methodName, 1)),
opt.upsert(true), null);