Convert mongo values from one encoding to another

1.8k Views Asked by At

I put 250_000 records to mongodb with java driver, but forgot to set encoding explicitly, so after linux on my windows machine system encoding changed to cp1251 and I have many records with values like Внедорожник 5 дв.

I have a solution - just to go throw all items, find and modify all string fields:

...
mc2.findOneAndUpdate(
    new Document("canonical", canonical), 
    new Document("$set", 
        new Document("regionName",
           new String(doc.getString("regionName").getBytes("cp1251"), "UTF-8"))));
...

Is there a way to do that without external program? (with some mongo js functions, utilities etc.)

0

There are 0 best solutions below