Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I am receiving this error when trying to delete a document from the database:

Cannot GET /delete/532fa5e56f885c7fec5223b1fds

How can I successfully delete the document?

app.js

//Delete

app.del('/delete/:id', routes.delete_offer);

routes/index.js

//Delete 

exports.delete_offer = function (req,res){ 

Offer.findOneAndRemove({'_id' : req.params.id}, function 

(err,offer){ 

res.redirect('/newsfeed'); 

}); 

};

views/dashboard.jade

- each offer in offers 

div.offer.row 

a(href="/offer/" + offer._id) 

div.columns 

div.sell_type 

p=offer.type

div.small-8.columns.sell_info 

p.sell_price="$" + offer.fixedPrice() + " " 

p.sell_location="@ " + offer.location + " ›" div.small-4.columns.sell_pic 

p=offer.user_id 

a.delete(href="/delete/" + offer._id)="Delete Offer"

1 Answer

0 votes
by (106k points)

To delete document using findOneAndRemove Mongoose you can fix file routes/index.js.

//Delete 

exports.delete_offer = function (req,res){ 

Offer.findOneAndRemove({_id : new mongoose.mongo.ObjectID(req.params.id)}, function (err,offer){ 

res.redirect('/newsfeed'); 

}); 

};

Related questions

0 votes
2 answers
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer

Browse Categories

...