与Pymong一起使用汉字

2024-06-02 04:49:12 发布

您现在位置:Python中文网/ 问答频道 /正文

def readTags(collection,index):
    file = open("F:\\dship\\odps-dship\\test_tag_data.txt")
    while True:
        line = file.readline()
        if not line:
            break
        strArr = line.split("\t")[8].split(" ")
        for index in range(len(strArr)):
            #queryTag = strArr[index]
            print(collection.find_one({"tagList":{"$all",u"手拿包"}}))

当我的程序执行时,我得到如下异常

bson.errors.InvalidDocument: Cannot encode object: set(['$all', u'\u624b\u62ff\u5305'])

我该怎么解决


Tags: testdataindexdeftaglineopenall
1条回答
网友
1楼 · 发布于 2024-06-02 04:49:12

对象表示法的Python语法几乎与所有MongoDB官方文档中常用的JSON表示法完全相同。唯一的例外是“ordered dicts”,它实际上是应用的,但在这种情况下不适用,因为没有需要特定顺序的键。你知道吗

因此,它基本上只是遵循^{}的文档实际所说的内容,与Unicode支持无关:

print(collection.find_one({ "tagList": { "$all": [ u"手拿包" ] } }))

是实际为您抛出错误的行的正确形式。对蒙哥达来说,你的语法没有错。你知道吗

相关问题 更多 >