🧵findByIdAndUpdate()

Example

import { Model, Schema, Types } from 'cherry3';

const schema = Schema({
name: String,
surname: Types.String,
age: Types.Number,
classNumber: Number,
achievements: { type: Array, default: [] },
closeFriends: Object
});

const model = new Model('classList',schema)

(async() => {

var result = await model.findByIdAndUpdate(1,{ $push:"Top student of the school" });
console.log(result)
/*
Old Data
{id:1, name: 'Paul', surname: 'Grey', age: 5, classNumber: 3, achievements:[]},

New Data
{id:1, name: 'Paul', surname: 'Grey', age: 5, classNumber: 3, achievements:["Top student of the school"]},
*/

})();

Last updated