There is mongo object
{
"_id" : ObjectId("5aa3abda9ff4d600da5b0168"),
"regionId" : NumberInt(3526),
"regionName" : "So Cal",
"categories" : [
"Other",
"Topicals",
"Tincture",
"Cannabis",
"Edibles",
"Extracts",
"Prerolled",
"Vape Cartridges"
]
}
Website object comes like this
{ "regionId" : 3526,
"regionName" : "So Cal",
"categories" : [
"Other",
"Seeds",
"Tincture",
"Cannabis",
"Edibles",
"Extracts",
"Prerolled",
"Vape Cartridges"
]
}
FINAL OBJECT SHOULD BE LIKE
{
"_id" : ObjectId("5aa3abda9ff4d600da5b0168"),
"regionId" : NumberInt(3526),
"regionName" : "So Cal",
"categories" : [
"Other",
"Seeds",
"Tincture",
"Cannabis",
"Edibles",
"Extracts",
"Prerolled",
"Vape Cartridges"
]
}
This object comes from a website and categories elements keep on changing. what I want to achieve is if some new element comes in categories then it should be inserted in my mongo and if some element is not there in the website and there in my mongo, it should be deleted from my mongo object.
$addToSet will only solve the problem if some new element is added but what in case of delete ?
(I'm an absolute beginner) in mongo please suggest how to achieve this.