Emoji not saved correctly in mongodb

跟風遠走 提交于 2019-12-11 10:43:52

问题


I am saving emoji from twitter and instagram into my mongodb database. But when i display the pulled data from the database. The emoji appear broken like this ❤️����������☀️��

Is there something i need to do different during saving data to mongodb, i am new to mongodb. I have read the emoji's use utf8-mb4 encoding but mongodb support only UTF8.


回答1:


UTF8 is the default encoding supported by MongoDB and support all characters (variable byte length) including utf8-mb4 (see below for further details). You are probably not converting your data to UTF-8 before uploading it to MongoDB or you are not treating the data as UTF-8 when retrieving the data.

Just to clarify, the original implementation "utf8" by MySQL was only for up to 3 bytes whereas the MySQL implementation called 'utf8-mb4' is actually up to 4 bytes long (like the official RFC recommends it).So utf8-mb4 in MySQL is the same as UTF8 in MongoDB.



来源:https://stackoverflow.com/questions/33035050/emoji-not-saved-correctly-in-mongodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!