From the course: MongoDB Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

updateOne and updateMany

updateOne and updateMany - MongoDB Tutorial

From the course: MongoDB Essential Training

updateOne and updateMany

- We already tried out the updateOne command a bit earlier but there are some things about it that we didn't cover. So let's go over this once more. To update one document in a collection you need to use the db.collection.updateOne() method. In the first part of the query you need to specify the query predicate. That means the condition that the document that you want to change needs to match. Be aware that if multiple documents match the document, only the first document that the database finds will be updated. Anyway, back to the query. The second part that you need to specify is what the query should change. So, let's do one more example of these, and let's go back to the database that we used in the beginning. So, let's use the blog database. So, let's briefly check which collections are available and we've got the authors collection. So, for the db.authors collection, let's just find the documents, okay. And now…

Contents