![]() |
VOOZH | about |
MongoDB is the most used cross-platform, document-oriented database that provides, high availability, high performance, and easy scalability. MongoDB works on the concept of collecting and documenting the data. findByIdAndRemove() stands proud as a convenient way to discover a file by its specific identifier and eliminate it from the database.
The findByIdAndRemove() function is part of the Mongoose library and is used to find a matching document, remove it, and pass the found document (if any) to the callback.
Step 1: Initialise an Express application with the following command.
npm init -yStep 2: Install the required dependencies.
npm install express mongooseFolder Structure
👁 ImageThe updated dependencies in package.json file will look like:
"dependencies": {
"express": "^4.18.2",
"mongoose": "^8.0.3"
}
Data collection before the operation.
👁 DatabaseExample: Add the following code in index.js file.
Steps to run the program:
node index.jsOutput