I am new to NodeJS.I was trying to create an api which will delete multiple users in a single go.I know how to delete single rows/user but getting stuck at multiple ones.
This is what i have done for a single user
var User = require('../models/User');
var moment = require('moment');
var jwt = require('jwt-simple');
var config = require('../config');
function createJWT(user) {
var payload = {
sub: user._id
, iat: moment().unix()
, exp: moment().add(14, 'days').unix()
};
return jwt.encode(payload, config.TOKEN_SECRET);
}
exports.createUser = function (req, res, next) {
var user = new User(req.userData);
user.save(function (err, result) {
if (err) {
res.status(500).send({
message: err.message
});
}
if(result.status == 'unverified')
return next();
else
res.send({
token: createJWT(result),
user : user
});
});
};
exports.removeUser = function(req, res){
User.findById(req.params.id).remove(function(){
res.redirect('/');
});
};
Can anyone help me out with this.
User.remove()which actually takes a query in argument. If that is the question then it's been answered long ago.