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.
Deleting documents in Java applications
From the course: MongoDB Java Developer Associate Cert Prep
Deleting documents in Java applications
- Hello, in this video, you'll learn how to use the deleteOne and deleteMany methods in the filters builder class for a Java application using MongoDB as its backing database. You can delete a single document from a collection by using the deleteOne method from a Mongo collection instance. For brevity, we'll assume that we have already instantiated the Mongo client and Mongo collection instances. The deleteOne method accepts a query filter that matches the document that you want to delete. It returns an instance of a DeleteResult, which contains information about how many documents were deleted. The following code deletes a single document from the accounts collection in the accounts database. This example uses the filters builder class method EQ to match an account belonging to John Doe. Then the deleteOne method is called to delete John doe's account. To confirm it was deleted, We print out the count of the number of deleted documents. If the deleteOne method is called with an empty…
Contents
-
-
-
-
-
-
-
-
-
Working with MongoDB documents in Java2m 33s
-
(Locked)
Inserting a document in Java applications2m 35s
-
(Locked)
Querying a MongoDB collection in Java applications2m 6s
-
(Locked)
Updating documents in Java applications2m 55s
-
(Locked)
Deleting documents in Java applications2m 2s
-
(Locked)
Creating MongoDB transactions in Java applications2m 52s
-
(Locked)
Review of MongoDB CRUD operations in Java1m 3s
-
-
-
-
-
-
-
-