通过邮递员进行删除和发布

时间:2019-06-25 05:31:40

标签: node.js mongodb

 second.delete('/students/:id', (req, res) => {
   const query = {role_num:req.body.role_num, first_name:req.body.first_name, last_name:req.body.last_name, marks:req.body.marks};
   db.collection('students').deleteOne(query, (err, obj) => {
        if (!err) {
           res.send('One document is deleted');
        } else {
          console.log(err);
        }
   })
});
second.post('/students/addStudent', (req, res) => {
  const newStudent = {role_num:req.body.role_num, first_name:req.body.first_name, last_name:req.body.last_name, marks:req.body.marks};
  db.collection('students').insertOne(newStudent,(err, obj) =>{
    if (!err) {
       res.send('New student added');
    } else {
      console.log(err);
    }
  })
});
second.put('/students/updateStudent/:id' ,(req, res) => {
  const newmarks = { first_name: req.body.first_name};
  const updatedStudent = {$set: { role_num:req.body,role_num, first_name: req.body.first_name} };
  db.collection('students').updateOne(newmarks, updatedStudent, (err,obj)=>{
    if (!err) {
       res.send('Updated student');
    } else {
      console.log(err);
    }
  })
});

因此,当我执行我的放置和发布操作时,上面已经动态编码了放置和删除内容,但看不到任何变化。当我执行删除操作时,我得到一些错误,指出role_num未定义

0 个答案:

没有答案