Database

db={"appusers":[{name:"person1",age:36,gender:"Male",preference:{age_from:28,age_to:35}},{name:"person2",age:18,gender:"Female",preference:{age_from:25,age_to:40}},{name:"person3",age:26,gender:"Female",preference:{age_from:30,age_to:35}},{name:"person4",age:26,gender:"Female",preference:{age_from:30,age_to:40}}]}

Query

db.appusers.aggregate([{"$match":{name:"person1"}},{$lookup:{"from":"appusers","let":{"a":"$age","gen":"$gender","pref":"$preference"},"pipeline":[{$match:{$expr:{$and:[{$ne:["$$gen","$gender"]},{$and:[{$or:[{$eq:[{"$ifNull":["$age","age-not-exists"]},"age-not-exists"]},{$and:[{$gte:["$age","$$pref.age_from"]},{$lte:["$age","$$pref.age_to"]}]}]},{$or:[{$eq:[{"$ifNull":["$$a","age-not-exists"]},"age-not-exists"]},{$and:[{$gte:["$$a","$preference.age_from"]},{$lte:["$$a","$preference.age_to"]}]}]}]}]}}}],"as":"matches"}}])

Result