You need to find the index of an existing comment.
Then you can overwrite the old comment with a new comment (where i is the index), for example:
post.comments[i] = new_comment
then just do post.save() and mongoengine will convert this to the $set operation.
Alternatively, you can simply write $set for example:
Post.objects(pk=post.pk).update(set__comments__i=comment)
Ross
source share