MongoDB & Node.js: Create an ACID Transaction (Part 3 of 4)
Ғылым және технология
✅ Sign-up for a free cluster at: mdb.link/free-bdS03tgD2QQ
✅ Get help on our Community Forums: mdb.link/community-bdS03tgD2QQ
In part three of this quick start tutorial for developers, Lauren Schaefer explains how to create ACID (atomicity, consistency, isolation, durability) transactions for MongoDB in a Node.js script. She explains how to use withTransaction() and a session to successfully complete or abort a transaction.
Chapters:
00:00 Intro
01:06 ACID transactions in MongoDB
04:06 The Setup
05:19 Create a Transaction
05:43 Create a Helper Function
07:50 Create a Function for the Transaction
17:59 Call the Function
20:54 Wrapping Up
Other videos in this tutorial series:
Part 1: • MongoDB & Node.js: Con...
Part 2: • MongoDB & Node.js: Agg...
Links Lauren mentions in the video:
Lauren's blog post: How to Use MongoDB Transactions in Node.js developer.mongodb.com/quickst...
Lauren's GitHub repo with the code from this video github.com/mongodb-developer/...
Lauren's script to create a "users" collection github.com/mongodb-developer/...
Node.js & MongoDB Starter Template File github.com/mongodb-developer/...
MongoDB Documentation: Convert a Standalone to a Replica Set docs.mongodb.com/manual/tutor...
Connect with Lauren:
Twitter: / lauren_schaefer
TikTok: / lauren_schaefer
Linkedin: / laurenjan...
MongoDB Community: developer.mongodb.com/communi...
Subscribe to MongoDB ►►► bit.ly/3bpg1Z1
Connect with MongoDB:
Website: bit.ly/2LjtNBZ
Twitter: bit.ly/3fH87gR
Facebook: bit.ly/3fEaIsd
Linkedin: bit.ly/2SY9w90
Instagram: bit.ly/3bn9bDv
Community Forums: bit.ly/2I8VCi5
TikTok: bit.ly/3fHoqdJ
Пікірлер: 32
✅ Sign-up for a free cluster at: mdb.link/free-bdS03tgD2QQ ✅ Get help on our Community Forums: mdb.link/community-bdS03tgD2QQ
Super awesome and straightforward explanation! Great work👍
very well explained. thanks!
I love this video. Thanks Lauren
superb content, easy to understand
Absolutely Awesome video infinite ❤️❤️❤️...
Transactions are needed to avoid concurrent modification related issues like read skew, phantom read, lost updates etc. Single threaded applications or where two transactions are accessible not-shared data are not prone to these errors, hence won't benefit from transactional overhead. We see a Single threaded usage of a transactions in the example which particularly does not solve any problems. Would you like to shed some light on what kinds of transaction Isolation it is using or we have options to use in Mongo. It would be really helpful to understand the transactional guarantees Mongo dB currently provides.
If I extended a schema with a custom method, which is usually a part of an outer transaction, is it a safe practice to pass session parameter to that method?
you are the best!! :)
2: in current case datesReserved is an array of only dates right? suppose if this array was a Subdocument we know the $in operator won't work . So in such situation which operator would we use to find a particular sub document in a collection ?
is the procedure for converting standalon mogodb to replica set same if i am using mongodb as a service ?
tnks very useful
3: can we use $each operator to add an object to a subdocument?
I get an error: The transaction was aborted due to an unexpected error: MongoServerError: The dollar ($) prefixed field '$date' in 'datesReserved.0.$date' is not valid for storage.
How would one go about maintaining a transaction for nested function calls? Like say for example a function A has some code in it and also calls function B. Now we can use session.withTransaction() in function A, but how do we use this same transaction for the database operations in function B? Do we pass the session variable as an argument to function B and use it in there?
@razbuchnik6007
Жыл бұрын
Yes. Exactly.
Thanks.
i have a few questions no 1: what is the difference between $push and $addToSet array operator? couldn't we use $push instead?
@mohammedsadiq1567
2 жыл бұрын
"addToSet" works just like it sounds - a *SET* It looks for duplicate entry. If the item already exists in the array, it doesn't do anything. If the item doesn't exist in the array, then it is added. With $push, it will add duplicate item.
inside catch always use console.error, to send message to correct stream
The session details are stored at the application level. What happens if the application server crashes mid-transaction?
@razbuchnik6007
Жыл бұрын
Good question. Interested as well please.
well it would be easier just to do reservation = { ...reservation, ...reservationDetails, }
I realy enjoyed first two tutorials, but this one definitely did not feel like quick start video. The example was so complicated, that for me, someone completely new to MongoDB, i got so lost in the complexity of the example, that i barely grasped how transactions work. Just replicating code without having any clue what i was doing. I would much prefer very simple example focused more on explaining how everything works for a "quick start" series. Previous videos were great tho and easy to understand.
I am new and I have a question @13:04 Author uses “datesReserved:{$in: reservationDates}” According to documentation the $in operator will look for documents where “value of a field equals any value in the specified array”. If datesReserved=[,], reservationDates=[,] and Another word does $in operator (1)checks for the range of time or it (2)checks for the individual time value of the conditional array? I would think (2) is the case according to the above documentation definition?
@thanghwang2208
Жыл бұрын
Ok, I've got it. the reservationDates is an Array listing all Dates (not a period fromDate to toDate as I assumed).
nice specks
I think the meaning of transaction is not described here? Is it editing two tables (collections) in one function? Why is it need to be emphasized that it is supported, isn't it common to be able to edit / work on multible tables?
Why do you need Node.js? Can't it be done in terminal?
Amazing tutorials. Also you have, like, super duper nice teeth lol
Page doesn't exists