Hi I am trying to delete an element which is inside array of array. my schema is :
var mySchema = Schema({
primaryField:String,
list1: [{
item1: String,
item2:String
}],
list2 : [{
item3:String,
item4 : [String]//item4 is string values available in item1
}]
});
for ex:
{
"primaryField": "abc",
"list1": [{
"item1": "aa",
"item2": "mystring"
},{
"item1": "bb",
"item2": "sampStr"
}],
"list2": [{
"item3": "stringitem",
"item4": ["aa", "bb"]
},{
"item3": "sample",
"item4": ["bb"]
},{
"item3": "samplestring",
"item4": ["aa"]
}]
}
I have to delete the "aa" items from list1 and the occurence of "aa" in list2.item4 and if only "aa" is present in item4 then i have to delete the entire object entry.
my output should be:
{
"primaryField": "abc",
"list1": [{
"item1": "bb",
"item2": "sampStr"
}],
list2:[{
"item3": "stringitem",
"item4": ["bb"]
},{
"item3": "sample",
"item4": ["bb"]
}]
}
could anyone help me to achieve this using node.js and mongoose. Schema cannot be modified.