2

During working on one c++ project we decided to use MongoDB database for storing some data of our application. I have spent a week linking and compiling c++ driver, and its works now. But it is one trouble: strings like

bob.append("name", "some text with cyrilic symbols абвгд");

are added incorrectly and after extracting from database look like 4-5 chinese symbols.

I have found no documentation about unicode using in mongodb, so I can not understand how to write unicode to database.

1 Answer 1

1

Your example, and the example code in the C++ tutorial on mongodb.org work fine for me on Ubuntu 11.10. My locale is en_US.UTF-8, and I the source files I create are UTF-8.

MongoDB stores data in BSON, and BSON strings are UTF-8, and UTF-8 can handle any Unicode character (including Cyrillic). I think the C++ API assumes strings are UTF-8 encoded, but I'm not sure.

Here are some ideas:

  • If your code above (bob.append("name"... etc) is in a C++ source code file, try encoding that file as UTF-8.
  • Try inserting Unicode characters via the mongodb shell.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.