Is there any way to atomically update two collections in MongoDB?

后端 未结 5 1240
轻奢々
轻奢々 2020-12-08 08:45

I have a collection of messages:

{
    messageid: ObjectId
    userid: ObjectId
    message: string
    isread: true|false
}

and a collecti

5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 09:16

    You could do this with trigger in sql. But in mongo, there is no trigger.

    You can perform operation on one of the document and check for LastErrorMessage on that operation by setting SafeMode.True

    Then if no error then update the second collection.

    Currently there is no way to do this in atomic way.

    If there is, I would have used in my project. I needed that functionality too.

提交回复
热议问题