How can I get pymongo to always return str and not unicode? -


from pymongo docs:

mongodb stores data in bson format. bson strings utf-8 encoded pymongo must ensure strings stores contain valid utf-8 data. regular strings () > validated , stored unaltered. unicode strings () encoded utf-8 first. > reason our example string represented in python shell u’mike’ instead of ‘mike’ pymongo decodes each bson string python unicode string, not regular str."

it seems bit silly me database can store utf-8 encoded strings, return type in pymongo unicode, meaning first thing have every string document once again call encode('utf-8') on it. there way around this, i.e. telling pymongo not give me unicode give me raw str?

no, there no such feature in pymongo; every string decoded bson decoded utf-8. python represents string internally ucs-2 or other format, depending on python version. see code bson decoder extracts string.

in upcoming pymongo 3.x series may add features more flexible bson decoding allow developers optimize uncommon use cases this.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -