{
category: "aaa",
// …. 其他字段
}
db.collection.updateMany(
{},
[{
$set: {
"category": {
$cond: {
if: { $eq: ["$category", "ALL"] },
then: ["AAA", "BBB"],
else: { $cond: { if: { $not: { $isArray: "$category" } }, then: ["$category"], else: "$category" } }
}
}
}
}]
)