Skip to content

Commit

Permalink
Creating delete API method
Browse files Browse the repository at this point in the history
  • Loading branch information
codingXpert committed Jul 23, 2022
1 parent 6e6c376 commit 000cf9d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion postApi.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const express = require('express');
const dbConnect = require('./dbConnFile');
const mongodb=require('mongodb');
const app = express();

//telling the node that we are using json data formate
Expand Down Expand Up @@ -30,6 +31,14 @@ let result = data.updateOne(
{$set:req.body}
)
res.send({result:"update"})
})
}) ;

//delete API
app.delete("/:id" , async(req , res)=>{
console.log(req.params.id);
const data = await dbConnect();
const result = await data.deleteOne({_id:new mongodb.ObjectId(req.params.id)});
res.send(result);
})

app.listen(8000);

0 comments on commit 000cf9d

Please sign in to comment.