Search code examples
mongodbaggregation-frameworkmongodb-compass

mongo Using a $match within an $and


I'm trying to use an $and within a $match and can't seem to get it correct. The syntax I'm using isn't correct.

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

Solution

  • Should be as simple as this:

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