Basically I have Post Document and Comment
EmbeddedDocument
as follow:
class Comment(EmbeddedDocument):
value1 = StringField(max_length=200,)
value2 = StringField(max_length=200,)
value3 = StringField(max_length=200,)
id = UUIDField(required=True, primary_key=True)
class Post(Document,):
comments = EmbeddedDocumentListField(Comment, required=False)
PUT
request may update any combination of value1, value2 and value3 for a given comment of a given post. I use queryset update
method to do that as follow:
post = Post.objects.get(id=post_id)
comment = None
for comm in post.comments:
if comm.id == comment_id:
comment = comm
Post.objects(
id=post_id,
comments__id=comment_id
).update(
set__comments__S__value1=new_value1 or comment.value1,
set__comments__S__value2=new_value2 or comment.value2,
set__comments__S__value3=new_value3 or comment.value3,
)
But this clearly not Read–modify–write atomic operation. So hot Read–modify–write as one atomic operation?