So the issue is I have nested objects in a and array that no longer exist in the related collection. The collection (users) searched through looks like
{
"_id" : id,
"locations" : [
{
"_id" : id,
"name" : name
}
]
}
The collection that the array relates to (locations) looks like.
{
"_id" : id,
"name" : name, ..........
}
So I'm running a map function to get all id and name in a map to reduce the fields to what I want to work with
vals = db.locations.find({},{
name : 1,_id : 1}).map(function(a){
return {
name : a.name,_id : a._id
};
})
Next I want to run an update which is something like this
db.users.update({
"locations" : {
"name" : {$nin : vals.name},
"_id" : {$nin : vals._id}}}, {
"$pull" : {
"array" : {
"name" : {$nin : vals.name},
"_id" : {$nin : vals._id }}}},
{ upsert: false, multi: true
})
But I'm not sure how to do this or if it's even possible.