表情符号未正确保存在mongodb中 [英] Emoji not saved correctly in mongodb

查看:814
本文介绍了表情符号未正确保存在mongodb中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Twitter和instagram中的表情符号保存到我的mongodb数据库中. 但是当我显示从数据库中提取的数据时. 表情符号看起来像这样破了❤️ ☀️

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 ❤️����������☀️��

在将数据保存到mongodb期间是否需要做一些其他事情,我是mongodb的新手. 我已经读过表情符号使用utf8-mb4编码,但是mongodb仅支持UTF8.

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.

推荐答案

UTF8是MongoDB支持的默认编码,并且支持包括utf8-mb4在内的所有字符(可变字节长度)(有关更多详细信息,请参见下文).在将数据上传到MongoDB之前,您可能没有将数据转换为UTF-8,或者在检索数据时未将数据视为UTF-8.

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.

仅需说明一下,MySQL的原始实现"utf8"最多只能使用3个字节,而称为"utf8-mb4"的MySQL实现实际上最多可以使用4个字节(如官方RFC建议的那样). MySQL中的-mb4与MongoDB中的UTF8相同.

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.

这篇关于表情符号未正确保存在mongodb中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆