I'm getting an error on robots.remove stating robots is not defined, But I can't possibly figure out exactly why. Please help. thank you.
mongoose.connect('mongodb://localhost/robots'); //connecting to localdb
router.delete('/:id', function(req,res){
var id = req.params.id;
console.log(id);
robots.remove({_id:ObjectId(id)}, function(err, result){ //undefined??
if (err) return res.status(500).send({err: 'Error: Could not delete robot'});
if(!result) return res.status(400).send({err: 'Robot bot deleted from firebase database'});
console.log('deleted!!!');
res.send(result);
});
});
robotsbeing "declared" anywhere. Surely you have more code than this. You should be calling somthing likerobots = mongoose.model("robots"), and also after an initial declaration of that model as well.requirethat module to import the model definition or alternately callmongoose.model"again" with the same model name as defined in your local scope. The error being reported is because their is no object declared in the local scope.