Is moving documents between collections a good way to represent state changes in MongoDB?

后端 未结 2 765
隐瞒了意图╮
隐瞒了意图╮ 2021-02-13 06:06

I have two collections, one (A) containing items to be processed (relatively small) and one (B) with those already processed (fairly large, wit

2条回答
  •  青春惊慌失措
    2021-02-13 06:48

    I've not tried this myself yet but the new book 50 Tips and Tricks for MongoDB Developers mentions a few times about using cron jobs (or services/scheduler) to clean up data like this. You could leave the documents in Collection A flagged for deletion and run daily job to clear them out, reducing the overall scope of the original transaction.

    From what I've learned so far, I'd never leave the database in a state where I rely on the next database action succeeding unless it is the last action (journalling will resend the last db action upon recovery). For example, I have a three phase account registration process where I create a user in CollectionA and then add another related document to CollectionB. When I create the user I embed the details of the CollectionB document in CollectionA in case the second write fails. Later I will write a process that removes the embedded data from CollectionA if the document in CollectionB exists

    Not having transactions does cause pain points like this, but I think in some cases there are new ways of thinking about it. In my case, time will tell as I progress with my app

提交回复
热议问题