我想在MongoDB字段中存储非英语(如:孟加拉语,印地语)数据.
This is my approach:- import pymongo from pymongo import MongoClient client = MongoClient() db = client.testdb db['testing'].save({'data':'??? ??????'})
我有一个例外.异常值:第5行的文件/test/views.py中的非ASCII字符'\ xe0',但未声明编码; 有关详细信息,请参阅http://www.python.org/peps/pep-0263.html(views.py,第5行)
之后我尝试过这样: -
from bson import BSON bson_string = BSON.encode({'data':'??? ??????'}) db['testing'].save({'data':'??? ??????'})
这次我也得到了同样的错误.
编辑: -基本上我不能够print '??? ??????'
在IDLE
>>>print '??? ??????' Unsupported characters in input
1ST EDIT
: - 我添加# -*- coding: utf-8 -*-
了我的views.py然后能够以某种方式存储数据.但是这个对象结构与mongodb中的普通数据结构不同.喜欢:-
> db['testing'].find() {ষ" } : ObjectId("52d65a50012bad0b23c13a65"), "data" : "শà§à¦ নববরà I have added another record. >db['testing'].save({'data':'kousik chowdhury'}) Now the collection is looking funny. > db['testing'].find() ষ" } { "_id" : ObjectId("52d65e6a012bad0a39a2685b"), "data" : "kousik chowdhury" }¦°à§ > db['testing'].find().length() 2
** I am using PuTTY as a editor. >>> a = db['testing'].find()[0] >>> a {u'_id': ObjectId('52d65a50012bad0b23c13a65'), u'data': u'\u09b6\u09c1\u09ad\u09a8\u09ac\u09ac\u09b0\u09cd\u09b7'} >>> mydata = a['data'] >>>mydata u'\u09b6\u09c1\u09ad \u09a8\u09ac\u09ac\u09b0\u09cd\u09b7' >>>mydata.encode('utf-8') '\xe0\xa6\xb6\xe0\xa7\x81\xe0\xa6\xad \xe0\xa6\xa8\xe0\xa6\xac\xe0\xa6\xac\xe0\xa6\xb0\xe0\xa7\x8d\xe0\xa6\xb7'
是否有任何标准流程,以便我可以以适当的格式存储在mongodb中并获取数据?