首页 > 解决方案 > mongo 在 $and 中使用 $match

问题描述

我试图在 $match 中使用 $and ,但似乎无法正确使用。我使用的语法不正确。

{
"$match":
{
                "$expr": {
                  "$and": [
                    {
                      "$match": {
                        "contra": {
                          "$exists": true
                        }
                      }
                    }
                    ,
                    {
                      "$match": {
                        "$expr": {
                          "$eq": [
                            "$isActivation", true
                          ]
                        }
                      }
                    }
                  ]
                }
}
}

标签: mongodbaggregation-frameworkmongodb-compass

解决方案


应该像这样简单:

{
    "$match": {
        "contractId": { "$exists": true },
        "isActive": true
    }
}

推荐阅读