Database

[{"user":"123","alerts":[{"alertDirection":"$gte","alertValue":9999,"location":"home","available":false,"position":28},{"alertDirection":"$lte","alertValue":50,"location":"home","available":true,"position":14},{"alertDirection":"$gte","alertValue":100,"location":"home","available":true,"position":71},{"alertDirection":"$gte","alertValue":100,"location":"out","available":true,"position":43}]}]

Query

db.collection.aggregate([{"$unwind":"$alerts"},{"$match":{"alerts.location":"home","alerts.available":true,"$expr":{"$cond":{"if":{"$eq":["$alerts.alertDirection",{"$literal":"$gte"}]},"then":{"$gte":[10,"$alerts.alertValue"]},"else":{"$lte":[10,"$alerts.alertValue"]}}}}},{"$group":{"_id":"$_id","user":{"$first":"$user"},"alerts":{"$push":"$alerts"}}}])

Result