S
S
Sergey Zenkovich2020-12-24 18:57:10
MongoDB
Sergey Zenkovich, 2020-12-24 18:57:10

PUT request does not work. Data in Mongodb doesn't change?

Hello!!! When working with the mongodb database, all queries work fine, except for PUT. >Cannot PUT /notes/5fe45811e6c6cc363004c238. And 404 drops out. What could be the problem?

app.put ('/notes/:id', (req, res) => {
        const myDB = database.db('test');
        const id = req.params.id;
        const details = { '_id': new ObjectID(id) };
        const note = { text: req.body.body, title: req.body.title };
        myDB.collection('notes').update(details, note, (err, result) => {
          if (err) {
              res.send({'error':'An error has occurred'});
          } else {
              res.send(note);
          } 
        });
      });

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