python - PyMongo 和 Discord.py 更新对象
问题描述
我正在尝试将 discord.py 与 PyMongo 集成,但现在我遇到了命令 update_one 的问题。 在此处输入图像描述
如您所见,“Corsi”是一种对象类型,我正在尝试使用这些命令向该对象添加字段。
@client.command(pass_context = True)
async def foo(ctx):
author = ctx.author.id
reg = {"_id": author}
collection.update_one({"_id": author}, {"$set": {"Corsi": {'test1': 89}}})
await ctx.message.channel.send("foo()")
#accedo ad un obj
@client.command(pass_context = True)
async def foo2(ctx):
author = ctx.author.id
reg = {"_id": author}
collection.update_one({"_id": author}, {"$set": {"Corsi": {'test2': 123}}})
await ctx.message.channel.send("foo2()")
#accedo ad un obj
当我使用命令 !foo2 时它工作正常,它将值 {test2:123} 添加到字段中,而当我在使用 !foo2 后使用命令 !foo 时,它将我的 {test2:123} 替换为 {test1:89}。
那么我怎样才能将新字段添加到对象中呢?
解决方案
推荐阅读
- javascript - 无法使用 react-router 访问 URL 路径组件
- azure-ad-b2c - 如何使用 Graph API(或任何其他方式)读取/更新 Azure B2C MFA 电话号码
- javascript - 如何编辑tbody上的所有td
- xml - 无法使用 xpath == "//*[text()[contains(.,' "+ word + " ')]]" 找到元素
- javascript - 反应,页面没有出现
- typescript - Hapi w/ TypeScript w/o 类型断言
- angular - RangeError:Angular 4 中超出了最大调用堆栈大小
- django - 在 django 模型中创建或更新另一个表的对象时自动创建模型对象
- jasper-reports - isStartNewPage=true 组在 jasper 中不工作
- python - Python 3.6v range() 函数不会执行