From the course: MongoDB Node.js Developer Associate Cert Prep
Unlock this course with a free trial
Join today to access over 25,000 courses taught by industry experts.
Updating documents in Node.js applications
From the course: MongoDB Node.js Developer Associate Cert Prep
Updating documents in Node.js applications
- Hello. In this video, you will learn how to perform single and multiple document updates in MongoDB with a Node.js application by using the updateOne() and updateMany() driver methods. In this example, we'll update the value of an existing field and add a new field and value. We use the updateOne() method when we need to update a single document that matches some specified criteria. The updateOne() method accepts a query filter and an update instruction. To demonstrate the updateOne() method, let's use the account documents in the accounts collection. We need to increase the balance of an account with a particular ID by 100. We can do this by defining the filter in update argument in the updateOne() method. The query filter finds an account with the account ID that we specify. Note that we have stored this in the documentToUpdate variable. The update argument use the $inc operator to increase the account's balance by…
Contents
-
-
-
-
-
-
-
-
- (Locked) Working with MongoDB documents in Node.js2m 50s
- (Locked) Inserting a document in Node.js applications3m 17s
- Querying a MongoDB collection in Node.js applications3m 7s
- (Locked) Updating documents in Node.js applications3m 5s
- (Locked) Deleting documents in Node.js applications1m 56s
- (Locked) Creating MongoDB transactions in Node.js applications3m 25s
- (Locked) MongoDB CRUD operations in Node.js review1m 8s
- (Locked)
-
-
-
-
-
-
-