I want to delete am item reference from restaurant when that item is deleted. What i did is, i made a method to pull out that item from restaurant but its not working. I found error like MongoError: Cannot apply $pull/$pullAll modifier to non-array.
here is my restaurant schema :
var Restaurant = new Schema({
name: [languageData],
description: [languageData],
phone: String,
email: String,
items: [{ type: ObjectId, ref: 'Item' }]
});
exports.restaurantModel = mongoose.model("Restaurant", Restaurant);
and this this my function to pull item from restaurant :
restaurantModel.update({'_id' : restId}, {'$pull': {'items': itemId}}, function(err,data){
if (!err) {
console.log("Refrence of Item is updated"+data);
} else {
console.log("Error : " +err);
}
});
i cant understand what is the problem. i have even tried to use multi : true and upsert : false but still there is an error.. Please help me out of this.