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

邮差的信 提交于 2021-01-05 06:37:28

问题


  • 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:


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


来源:https://stackoverflow.com/questions/62407638/mongoerror-expression-in-takes-exactly-2-arguments-1-were-passed-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!