i am working on nodejs/express
I want to delete element in array in mongoose
i have document in this format
{
"_id" : ObjectId("5a2e19223e50551504b316c0"),
"username" : "nikhil",
"email" : "[email protected]",
"password" : "$2a$10$f3NvrTywIezlzKcZLWSU0O98gn6Mc.Q8B0ZNEDG2F66f4rwyo65Yu",
"companyname" : "itr",
"role" : "vendor",
"verify" : "true",
"createddate" : ISODate("2017-12-10T18:30:00.000+0000"),
"account" : [
{
"Region" : [
"North America",
"Africa",
"Asia"
]
},
{
"Category" : [
"Group 1",
"Group 2",
"Group 3"
]
}
]
}
i want to remove only Region field using mongoose query i m getting data dyanamically so user can delete any array either it is Region or Category. i m getting array name which i want to delete in parameter "field".
module.exports.setupAccount = function(id,field,callback){
var query = { _id: id};
User.findOneAndUpdate(query,{ $set: { account.Region:[] }}, callback);
}
i am new to nodejs and mongoose thanks in advance