Database
[{"name":"Maths","excludeUserIds":[{"_id":33,"groupIds":["a","b","c"]}]},{"name":"Science","excludeUserIds":[{"_id":24,"groupIds":["a","x","b"]}]},{"name":"Health","excludeUserIds":[]},{"name":"English","excludeUserIds":[{"_id":33,"groupIds":[]}]}]
Query
db.collection.aggregate([{"$match":{"excludeUserIds":{"$elemMatch":{"_id":{$ne:33},"groupIds":{"$elemMatch":{$nin:["a"]}}}}}}])