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

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