“Обновление мангуза” Ответ

Монгуз найти и обновить опору

var query = {'username': req.user.username};
req.newData.username = req.user.username;

MyModel.findOneAndUpdate(query, req.newData, {upsert: true}, function(err, doc) {
    if (err) return res.send(500, {error: err});
    return res.send('Succesfully saved.');
});
florinrelea

обновление мангуоза и вернуть новый

const query = {} //your query here
const update = {} //your update in json here
const option = {new: true} //will return updated document

const user = await User.findOneAndUpdate(query , update, option)
Graceful Gerenuk

Обновление мангуза

   Modelomodel
      .findOne({ Id: Id })
      .update(body)
      .exec()
Zarden

сохранение или обновление мангуза

// This will create another document if it doesn't exist
findByIdAndUpdate(_id, { something: 'updated' }, { upsert: true });
florinrelea

Mongoose UpdateOne Пример

// Update the document using `updateOne()`
await CharacterModel.updateOne({ name: 'Jon Snow' }, {
  title: 'King in the North'
});

// Load the document to see the updated value
const doc = await CharacterModel.findOne();
doc.title; // "King in the North"
Lonely Loris

Обновление мангуза

// Update a user's info, by username
/* We’ll expect JSON in this format
{
  Username: String,
  (required)
  Password: String,
  (required)
  Email: String,
  (required)
  Birthday: Date
}*/
app.put('/users/:Username', (req, res) => {
  Users.findOneAndUpdate({ Username: req.params.Username }, { $set:
    {
      Username: req.body.Username,
      Password: req.body.Password,
      Email: req.body.Email,
      Birthday: req.body.Birthday
    }
  },
  { new: true }, // This line makes sure that the updated document is returned
  (err, updatedUser) => {
    if(err) {
      console.error(err);
      res.status(500).send('Error: ' + err);
    } else {
      res.json(updatedUser);
    }
  });
});
Quaint Quelea

Ответы похожие на “Обновление мангуза”

Вопросы похожие на “Обновление мангуза”

Больше похожих ответов на “Обновление мангуза” по JavaScript

Смотреть популярные ответы по языку

Смотреть другие языки программирования