1 00:00:02,230 --> 00:00:06,890 So here I am connected to that mongodb Atlas server in the web 2 00:00:07,210 --> 00:00:09,780 and I will use a new database, 3 00:00:09,780 --> 00:00:13,260 blog and in there, let's quickly insert some dummy data. 4 00:00:13,300 --> 00:00:18,790 Let's insert a users collection and I'll insert one user here, 5 00:00:18,820 --> 00:00:20,380 I'll make this really simple, 6 00:00:20,380 --> 00:00:24,910 I'll have a user with the name of Max. That is my one user, 7 00:00:24,910 --> 00:00:31,870 now I got a user ID and I will copy that ID because now I'll add a posts collection where I insert many 8 00:00:31,870 --> 00:00:34,520 posts, therefore I need an array here 9 00:00:34,660 --> 00:00:41,920 and then the first post has a title of first post and important, a user ID at which it points, 10 00:00:41,920 --> 00:00:44,260 so here I'll use a relation with references. 11 00:00:44,260 --> 00:00:50,120 Check out the relations module in this course if you want to learn more about data schemas and relations. 12 00:00:50,140 --> 00:00:57,190 So here I'll just store that ID and then I'll add a second post here with a title of second post and 13 00:00:57,190 --> 00:00:59,520 that post will have been created by the same user, 14 00:00:59,530 --> 00:01:02,120 so I store the same ID as a value here. 15 00:01:02,260 --> 00:01:05,660 If I hit enter, these two posts are also created. 16 00:01:05,740 --> 00:01:11,680 Now if we want to delete the user, we would obviously find out the user id and that is probably something 17 00:01:11,680 --> 00:01:15,940 you know in the application where the user clicked on delete my account, 18 00:01:15,940 --> 00:01:24,070 so in the end you would do something like db users delete one and then search for _id equal 19 00:01:24,070 --> 00:01:27,700 to that user ID which you know. Now you would do that 20 00:01:27,880 --> 00:01:37,160 and then with that user ID which you do know, you would of course also go ahead and also execute db 21 00:01:37,580 --> 00:01:42,820 products delete many and delete all products where the user ID, 22 00:01:42,860 --> 00:01:48,570 so that field which I added to each post where we point at the user is equal to the user id too. 23 00:01:48,740 --> 00:01:53,060 I won't execute these commands because I don't want to delete the data right now but this is how we 24 00:01:53,060 --> 00:01:56,600 could clear all the data and this would work in 99.9% 25 00:01:56,600 --> 00:02:02,840 of cases. The problem just is the cases where it doesn't work because something goes wrong and 26 00:02:02,840 --> 00:02:08,850 we end up in a state where it suddenly, well we deleted the user but not the posts or the other way around 27 00:02:08,930 --> 00:02:11,720 and for that, we can work with transactions. 28 00:02:11,720 --> 00:02:13,610 Now how does a transaction work? 29 00:02:13,700 --> 00:02:15,870 Let's dive into that in the next lecture.