Delete method Api in Nodejs

Create the delete method API to delete the document from the MongoDB.

var express = require('express');
var app = express();
app.delete('/deleteUser/:id', function (req, res) {

    MongoClient.connect(url, function (err, db) {


    let req_params=req.params;

    let user_id=(typeof !== 'undefined') ? (;
    db.collection("users").deleteOne({"_id":user_id},function(err, result) {

    if (err){
      res.json({data:result,messages:"some thing went wrong",status:501})

   res.json({data:result,messages:"user delete successfully",status:200})



   res.json({data:err,messages:"some thing went wrong",status:501})



Note:- In the above example req.params is used to get route parameters value.
I think hard delete record is not good so we should use soft delete.