From the course: MongoDB Node.js Developer Associate Cert Prep

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Updating MongoDB documents by using updateOne()

Updating MongoDB documents by using updateOne()

From the course: MongoDB Node.js Developer Associate Cert Prep

Updating MongoDB documents by using updateOne()

- Welcome. In this video, you'll learn how to use common update operators in the MongoDB shell. First, we'll discuss the updateOne method, which we'll use with two common update operators, set and push. Then we'll go over how to use an option called upsert. Let's start with updateOne. This method updates a single document. It accepts three arguments, a filter document, an update document, and an options object. The first argument, the filter document contains the selection criteria for the update. The second argument, the update document contains an update operator expression that will be used in the update. The third argument is an options object. Note that options is not a required argument. When updating documents we can use operators like set or push with update methods like updateOne. The set operator does one of two things. It adds new fields and values to a document or it replaces the value of a…

Contents