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.
Deleting documents in Node.js applications
From the course: MongoDB Node.js Developer Associate Cert Prep
Deleting documents in Node.js applications
- Hello, in this video you will learn how to use the deleteOne and deleteMany methods for a Node.js application with MongoDB. We can delete a single document from a collection by using the deleteOne method. The deleteOne method accepts a query filter that matches the document you want to delete. It returns a delete result, which contains information about how many documents were deleted. The following code deletes a single document from the accountsCollection in the bank database. The example uses a filter document called documentToDelete to match an account with the _id value. Then we pass the filter documentToDelete to the deleteOne method to delete the account. We confirm that the document was deleted by checking the result message. If the deleteOne method is called with an empty query filter, then it matches and deletes the first document in the collection. Multiple documents can be deleted from a collection…
Contents
-
-
-
-
-
-
-
-
- (Locked) Working with MongoDB documents in Node.js2m 50s
- (Locked) Inserting a document in Node.js applications3m 17s
- Querying a MongoDB collection in Node.js applications3m 7s
- (Locked) Updating documents in Node.js applications3m 5s
- (Locked) Deleting documents in Node.js applications1m 56s
- (Locked) Creating MongoDB transactions in Node.js applications3m 25s
- (Locked) MongoDB CRUD operations in Node.js review1m 8s
- (Locked)
-
-
-
-
-
-
-