From the course: MongoDB Java Developer Associate Cert Prep

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Updating documents in Java applications

Updating documents in Java applications

- Hello. In this video you'll learn how to perform single and multiple document updates in MongoDB with a Java application. To do this, we'll use the updateOne() and updateMany() Mongo collection methods. Two ways to update a document in Mongo DBR, update the value of an existing field or define a new field in value. Note that this is not an exhaustive list of available update operations. For brevity, we'll assume that the Mongo client and Mongo collection instances have been already initialized. We use the Mongo collection 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 document. To demonstrate the updateOne() method, let's assume that we have bank account documents and an accounts collection, and we need to increase the balance of John Doe's account by 100. Additionally, we want to add an account status field that shows if the account is active or dormant. To do this, we'll…

Contents