我在机器人上收到错误。删除说明机器人没有定义,但我无法弄明白为什么。请帮忙。谢谢。
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);
});
});
答案 0 :(得分:4)
您必须先加载用户模型。
var robots = require('../app/models/robots');//Load the model
robots.js文件应如下所示:
var mongoose = require('mongoose');
var robotSchema = mongoose.Schema({
//Your schema here
});
module.exports = mongoose.model('robots', robotSchema);