javascript - MongoDB 检查 $switch 语句中的空字段
问题描述
我试图检查我的 $switch 语句中的空/缺失字段,但它不起作用。这是我的代码
$switch: {
branches: [
{
case: {
$and: [
{ $gte: ["$SmartPriority", 6] },
{ $ne: ["$FlashTRFPromotionDate", null] },
{ $ne: ["$FlashTRFPromotionDate", ""] },
{ $ne: ["$FlashTRFPromotionDate", false] }
]
},
then: "Greater than"
}
],
default: "EMPTY"
}
即使 $ne 为“null”或“false”,它也不会显示 EMPTY(默认值)。我的表情应该是什么?
解决方案
它应该是这样的
"$switch": {
"branches": [
{ "case": { "$gte": ["$SmartPriority", 6] }, "then": "Greater than" },
{ "case": { "$ne": ["$FlashTRFPromotionDate", null] }, "then": "EMPTY" },
{ "case": { "$ne": ["$FlashTRFPromotionDate", ""] }, "then": "Greater than" },
{ "case": { "$ne": ["$FlashTRFPromotionDate", false] }, "then": "EMPTY" }
],
"default": "EMPTY"
}
推荐阅读
- swift - Swift: Rounded Buttons
- scala - 如何重新启动被杀死的演员?
- java - 如何在我的 FXML 中显示和访问在 Java 类中创建的 ComboBox?
- reactjs - 动态更新 react-table 中可用记录数的计数
- java - Spring Batch StoredProcedureItemReader for PostgreSQL - java.lang.IllegalStateException
- algorithm - 如何在没有邻接矩阵的情况下有效地找到图中的连通分量?
- pandas - 你可以使用 matplotlib 制作 4 列数据的 4 条柱吗?
- java - 如何修复javac包不存在?
- python - 将十进制转换为二进制,如何获得 8 位二进制?
- css - react-native scrollView 不适合我