app.post("/delete", function(req,res){
var deluser = req.body.usernamedel;
var reason = req.body.reason;
User.remove({name: deluser}, function(err, user){
if(err){
console.log(err)
} else {
console.log(user);
}
}).exec();
});
I'm trying to get this post request to pull the name from the page and then remove it from the database, but it doesn't seem to remove it. All it shows in the console is this -{ n: 0, ok: 1 }- which I don't know what means. How do I make the command actually delete the user?
n: 0essentially says that nothing actually matched the query condition given in argument, so there is no data in your collection matching{ name: deluser }for the value you are providing. In all likelihood, you actually issued the same request multiple times, and initially it would have been{ n: 1, ok: 1 }indicating that1( or possibly a larger number of matches ) document was matched and removed. Theok: 1of course means there was no error.req.body.usernamedelis not actuallly what you think it is. Check your collection, and then also check the input you are providing with something likeconsole.log(deluser)and see what the actual input value being sent really is.mongooseand that means yourUsermodel is expecting "by default" to see a collection namedusers. If your actual collection is nameduseror evenUserin MongoDB, then there is another way to tell mongoose to use that name instead.