1

How to store non utf-8 strings such as "\xac\xbb,v\xc9o\xa8\x18\x89\x95\xd8K\x03AZ\xac" in mongodb using pymongo?

If I do it using the usual way, i get a error message "strings in documents must be valid UTF-8: '\xac\xbb,v\xc9o\xa8\x18\x89\x95\xd8K\x03AZ\xac'"

1 Answer 1

1

You have two options:

  1. convert the string from its current encoding into UTF-8, as MongoDB only supports UTF-8 encoded strings in documents; you can use python's string encoding functions for this

  2. store the string as binary data in a binary type field, using the binary submodule in PyMongo.

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.