Mongoose | remove() Function Last Updated : 08 Jan, 2025 Comments Improve Suggest changes Like Article Like Report The remove() function is used to remove the documents from the database according to the condition. Installation of mongoose module:You can visit the link to Install mongoose module. You can install this package by using this command. npm install mongooseAfter installing mongoose module, you can check your mongoose version in command prompt using the command. npm version mongooseAfter that, you can just create a folder and add a file, for example index.js. To run this file you need to run the following command. node index.jsFilename: index.js javascript const mongoose = require('mongoose'); // Database Connection mongoose.connect('mongodb://127.0.0.1:27017/geeksforgeeks', { useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true }); // User model const User = mongoose.model('User', { name: { type: String }, age: { type: Number } }); User.remove({age:{$gte:30}}, function (err, result) { if (err){ console.log(err) }else{ console.log("Result :", result) } }); Steps to run the program:The project structure will look like this: Make sure you have installed mongoose module using following command: npm install mongooseBelow is the sample data in the database before the function is executed, You can use any GUI tool or terminal to see the database, like we have used Robo3T GUI tool as shown below: Run index.js file using below command: node index.jsAfter the function is executed, You can see the database as shown below: So this is how you can use the mongoose remove() function which removes the documents from the database according to the condition. Comment More infoAdvertise with us Next Article Mongoose | remove() Function G gouravhammad Follow Improve Article Tags : JavaScript Web Technologies Node.js MongoDB Mongoose +1 More Similar Reads Mongoose update() Function In Mongoose, the update() function is used to modify a document in a MongoDB collection based on a given filter. It updates a document but does not return the updated document itself. This function is part of Mongooseâs Query API and is a powerful tool for managing data in your Node.js applications. 5 min read Mongoose.model() Function The mongoose.model() function is a core method in the Mongoose library, used for interacting with MongoDB in a Node.js environment. It helps in creating a MongoDB collection associated with a schema, defining the structure of documents that will be stored within it. This article will explain mongoos 4 min read Mongoose Document Model.remove() API The Model.remove() method of the Mongoose API is used to remove all the documents present in the collection in one go. It will be called on a Collection model which is already defined and present in the database. Syntax: Model.remove() Parameters: The Model.remove() method accepts two parameters: o 3 min read Node.js fs-extra remove() Function the remove() function deletes the given file or directory. All the files inside a directory are deleted. If the given file or directory does not exist the function will do nothing. Syntax: fs.remove(path,callback) Parameters: This function accepts two parameters as mentioned above and described belo 1 min read Mongoose Queries Model.updateOne() Function The Model.updateOne() function in Mongoose is a powerful method used to update a single document within a MongoDB collection. It allows you to specify the conditions for selecting a document and then provides a way to apply updates to that document. In this article, we will explore how updateOne() w 4 min read Like