-
$mapall_usersのループを繰り返す 配列 -
$condidの場合は条件を確認してください 選択したユーザーのidにあります 次に、selectedで「yes」または「no」を返します。 フィールド -
$mergeObject現在のユーザーオブジェクトを上記のselectedとマージします フィールド
db.collection.aggregate([
{
$project: {
all_users: {
$map: {
input: "$all_users",
in: {
$mergeObjects: [
"$$this",
{
selected: {
$cond: [
{ $in: ["$$this.id", "$selected_users.id"] },
"yes",
"no"
]
}
}
]
}
}
}
}
}
])