Вы можете запустить следующий конвейер агрегации:
db.collection.aggregate({
$project: {
"foundIn": {
$cond: [
// if the filtered "up" array does not equal an empty array []
{ $in: [ userId, "$up" ] },
// then return "up"
"up",
{
// otherwise we apply the same logic for "down"
$cond: [
{ $in: [ userId, "$down" ] },
"down",
// fall back to "nowhere" result if the searched value is not contained in either array
"nowhere"
]
}
]
}
}
})