MongoDB在$switch语句中检查空字段

4

我尝试在 $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(默认值)。我的表达式应该是什么?
1个回答

2
应该是这样的:

它应该像这样

"$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"
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接