findbyidandupdate mongoose code example
Example 1: findbyidandupdate return old value
Model.findByIdAndUpdate(id, updateObj, {new: true}, function(err, model) {...
Example 2: mongoose findoneandupdate
const doc = await CharacterModel.findOneAndUpdate(
{ name: 'Jon Snow' },
{ title: 'King in the North' },
{ new: true }
);
doc.title;
Example 3: mongoose model
const schema = new mongoose.Schema({ name: 'string', size: 'string' });
const Tank = mongoose.model('Tank', schema);
Example 4: model mongoose
const modelName = mongoose.model("collectionname", collectionSchema);
const fruitSchma = new mongoose.Schema ({
name: String
});
const Fruit = mongoose.model("Fruit", fruitSchema);