Many to many update in MongoDB without transactions

前端 未结 3 923
死守一世寂寞
死守一世寂寞 2021-02-14 20:08

I have two collections with a many-to-many relationship. I want to store an array of linked ObjectIds in both documents so that I can take Document A and retrieve all linked Doc

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-14 20:57

    Should I use safe mode and manually check the data went in afterwards and try again on failure?

    Yes this an approach, but there is an another - you can implement an optimistic transaction. It has some overhead and limitations but it guarantees data consistency. I wrote an example and some explanation on a GitHub page.

提交回复
热议问题