V
V
Valery Orlov2018-11-12 11:09:22
JavaScript
Valery Orlov, 2018-11-12 11:09:22

How to delete the found entry from the database?

The code below displays the commands field from the collection. Help form it so that, before the output, the res.statusfound record is deleted from the database and only then displayed.

Commands.find({ 'device': req.body.id })
  .exec()
  .then(cmd => {
    if(cmd.length = 1){
        res.status(200).json({
          "commands": cmd[0].commands,
          "result":"ok",
        });
    }
  })
  .catch(err => {
    console.log(err);
    res.status(500).json({
      error: err
    });
  });

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question