mongodb中关于中文乱码问题的处理.docx
《mongodb中关于中文乱码问题的处理.docx》由会员分享,可在线阅读,更多相关《mongodb中关于中文乱码问题的处理.docx(2页珍藏版)》请在三一办公上搜索。
1、mongodb中关于中文乱码问题的处理mongodb中关于中文乱码问题的处理 经过几番处理,终于将这个问题解决了,以免其他mongodb使用者在由遇到相同问题时不知所措,特写下处理过程如下: 测试代码如下 1 namespace Test 2 3 class Program 4 5 static void Main(string args) 6 7 try 8 9 string conn = mongodb:/localhost; 10 MongoServer server = MongoServer.Create(conn); 11 MongoDatabasedb = server.GetD
2、atabase(bar); 12 MongoCollection persons = db.GetCollection(persons); 13 persons.RemoveAll; 14 15 #region mongodb新增测试 16 string chineseName = 李小龙; 17 BsonDocument person = new BsonDocument 18 chineseName, chineseName, 19 englishName, Bruce Lee 20 ; 21 22 persons.Insert(person); 23 24 var found = per
3、sons.FindOneAs; 25 varnameInDatabase = foundchineseName; 26 Console.WriteLine(the value are0 equle, (nameInDatabase = chineseName) ? : not ); 27 #endregion 28 29 catch (Exception ex) 30 31 Console.WriteLine(ex.Message); 32 33 finally 34 35 Console.ReadKey; 36 37 38 39 40 经过上面的插入,后台数据库中再次查询时就会出现乱码,但程序中确显示正常,这主要是因为cmd窗口的编码方式引起的,因为mongodb后台的字符编码都是utf-8的,所以修改cmd窗口的编码如下: (1)chcp 65001 (2)选择“属性”中的字体,除“点阵字体”外所有的都行 再次运行就显示正常了。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- mongodb 关于 中文 乱码 问题 处理

链接地址:https://www.31ppt.com/p-3161677.html