MongoError: Expression $in takes exactly 2 arguments. 1 were passed in

Viewed 3979
  • below is my query: while executing below query getting mongoerror : Expression $in takes exactly 2 arguments. 1 were passed in. i am using $in Comparison operator

    {
        "$expr": {
            "$not": {
                "$eq":{
                    "$and": [
                        {
                            "PrName": {
                                "$in": [
                                    "pname"
                                ]
                            }
                        },
                        {
                            "AccountId": {
                                "$in": [
                                    "34562",                      
                                    "88765",
                                    "87654",
                                    "12345"
                                ]
                            }
                        }
                    ]
                }
            }
        }
    }
    
1 Answers

When you use $expr, the operator expressions syntax changes a little:

{ $in: [ <expression>, <array expression> ] }

{
  "$expr": {
    "$not": {
      "$and": [
        {
          "$in": [
            "$PrName",
            [
              "pname"
            ]
          ]
        },
        {
          "$in": [
            "$AccountId",
            [
              "34562",
              "88765",
              "87654",
              "12345"
            ]
          ]
        }
      ]
    }
  }
}
Related