I need to take array from my model, delete from it some days and push to it some other days. It looks something like deleteAndUpdate
.
To sum up: I need to take Car
from database. Take reserved
property (it's a array), then delete from reserved
days from given list, and then add to reserved
days from other given list.
My model look:
const CarSchema = mongoose.Schema({ mark:{ type: String, required: true,}, model:{ type: String, required: true,}, price:{ type: Number, required: true,}, available: { type: Boolean, required: true,}, reserved:{ type:[Date], }, pic_1:{ type:String, required:true, }, pic_2:{ type:String, required:true, }, }, { collection: 'cars' } )
I take car by: var car= await Car.findById(carID);
and then i need to do sth like that:
car['reserved'].deleted(old_days); car['reserved'].push(new_days; car.save();
Could someone help me?
https://stackoverflow.com/questions/67238999/mongoose-deleting-and-updating-in-array April 24, 2021 at 11:11AM
没有评论:
发表评论