I have been struggling for a while now and i can't seem to find an answer here. I want to filter an array of subschemas in a subdocument by removing the ones that exist in an already specified list (using $nin:). My problem is that the list I want to check against is on the parent of the sub document, take a look at what I want to do:
User.find({_id : socketUser.User})
.populate("room")
.elemMatch("room.things", {"Id" : {$nin : "User.likedThings" }})
.exec(function(err,users){
console.log(err);
});
So my user has an attribute called room in while I have a list of things. The user also has an array of unique ids (not ObjectIds, strings) of "likedThings".
What I want to do is to get the "Things" for the room which ids are not already in the users list of "likedThings".
My issue is that I can't access User.likedThings when I am "down" in room. ( there is no ../../ -like command).
How do I achieve this?