🧵findOneAndUpdate()

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.findOneAndUpdate({ classNumber: 7 },{ $pull:"reading" });
console.log(result)
/*
Old Data
{id:2, name: 'Jesse', surname: 'Clean', age: 5, classNumber: 7, achievements:["reading"]},

New Data
{id:2, name: 'Jesse', surname: 'Clean', age: 5, classNumber: 7, achievements:[]}
*/

})();

Last updated