Qual é a maneira correta de atualizar um campo de listagem de documentos incorporados no mongoengine?
Estou tentando definir métodos para executar verificações e atualizações em um campo de listagem de documentos incorporados no mongoengine. Qual é a maneira correta de fazer o que estou tentando fazer? O código está abaixo.
class Comment(EmbeddedDocument):
created = DateTimeField()
text = StringField()
class Post(Document):
comments = ListField(EmbeddedDocumentField(Comment))
def check_comment(self, comment):
for existing_comment in self.comments:
if comment.created == existing_comment.created and
comment.text == existing_comment.text:
return True
return False
def add_or_replace_comment(self, comment):
for existing_comment in self.comments:
if comment.created == existing_comment.created:
# how do I replace?
# how do I add?
Esta é a maneira correta de fazer algo assim?