gpt4 book ai didi

python - 无法对对象 : pymongo. 光标进行编码。光标对象位于

转载 作者:太空宇宙 更新时间:2023-11-03 15:09:06 24 4
gpt4 key购买 nike

当抛出上述错误时,我正在尝试检索存储在 MongoDB 中的音频文件。

代码如下:

elif json_data != None and 'retriever' in json_data:
query_param = json_data['retriever']
data = db.soundData
x = data.find({'name': query_param})
y = data.find({'data': x})
return Response(y, mimetype='audio/mp3')

name下我有文件的名称,在data下是音频文件本身。由于我是 pymongo 的新手,有人可以指出错误可能来自哪里吗?

最佳答案

首先,你need not be saving your file itself in mongo您应该保存的是文件名,文件本身最好保存在文件系统上。

出现该错误是因为 x 和 y 确实是 mongodb 游标,而不是您期望的数据。您应该使用find_one相反。

find_one(filter=None, *args, **kwargs) Get a single document from the database.

All arguments to find() are also valid arguments for find_one(), although any limit argument will be ignored. Returns a single document, or None if no matching document is found.

y = data.find_one({'data': x})

您可以使代码更加简洁

y = data.find_one({'data': {'name': query_param}})

关于python - 无法对对象 : pymongo. 光标进行编码。光标对象位于,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44378828/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com