Mongoose Restaurant Schema
const mongoose=require('mongoose');
const RestaurantSchema=mongoose.Schema(
{
_id:{type:mongoose.Schema.Types.ObjectId,required:true},
restaurantName:{type:String,required:true},
phone:{type:String,required:true},
offer: [{type:mongoose.Schema.Types.ObjectId,ref:"Offer"}]
});
module.exports=mongoose.model("Restaurant",RestaurantSchema);
Updating method
Restaurant.findByIdAndUpdate(userid, { offer:[ "offerObjectId" ]},
function (err, docs) {
if (err) {
console.log(''+err);
res.status(500).json({
messahe:err
});
}
else {
console.log("restaurant : ", docs);
res.status(201).json({
messahe:docs
});
}
});
while i using above method to update new offer, that's overwriting previous offers in array data, But I want to keep my previous data, while i updating new offer, How can i achieve that?