如何在MongoDB Field中存储不同的语言(非英语)数据并检索相同的数据?

 老屋时光_503 发布于 2023-02-03 12:27

我想在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中并获取数据?

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有