gpt4 book ai didi

python - 如何更新 Graphite 烯mongo python中EmbeddedDocument的字段

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

我正在尝试更新 IgThread EmbeddedDocument 的一个字段,并且发生错误:“IgThread”对象没有属性“save”

我尝试了一些奇怪的解决方案,但没有一个有效。当前代码存在错误

突变:

def mutate(self, _, **kwargs):
ig_pk = kwargs['ig_pk']
thread_input = kwargs['ig_thread']

lead_ = Lead.objects(ig__pk=ig_pk).first()

for thread in lead_.messages.ig:

Lead.objects(
ig__pk=ig_pk,
messages__ig__thread_id=thread_input.thread_id,
).update(
push_all__messages__ig__S__messages=new_messages,
)

thread.last_activity_at = thread_input.last_activity_at
thread.save()

父级:

class Lead(Document):
id = fields.ObjectIdField()
messages = fields.EmbeddedDocumentField(Messages)

嵌套嵌入文档:

class Messages(EmbeddedDocument):
ig = fields.EmbeddedDocumentListField(IgThread)

更深入:

class IgThread(EmbeddedDocument):
thread_id = fields.StringField()
last_activity_at = fields.StringField()

我想更新last_activity_at请帮忙,我必须修复这个错误,但在办公室里没有人能帮我解决这个问题:<

最佳答案

解决了!这很容易...

def mutate(self, _, **kwargs):
ig_pk = kwargs['ig_pk']
thread_input = kwargs['ig_thread']

lead_ = Lead.objects(ig__pk=ig_pk).first()

for thread in lead_.messages.ig:

Lead.objects(
ig__pk=ig_pk,
messages__ig__thread_id=thread_input.thread_id,
).update(
push_all__messages__ig__S__messages=new_messages,
)

lead_ = Lead.objects(ig__pk=ig_pk).first() <--------
thread.last_activity_at = thread_input.last_activity_at
lead_.save() <--------

关于python - 如何更新 Graphite 烯mongo python中EmbeddedDocument的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57150314/

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