{"record":{"id":"44bfb0300dd78645","repo":"mongodb/mongoid","slug":"operator-argument-must-be-an-array-errors-i","errorCode":null,"errorMessage":"#{operator} argument must be an array: #{Errors::InvalidQuery.truncate_expr(op_expr)}","messagePattern":"#(.+?) argument must be an array: #(.+?)","errorType":"exception","errorClass":"Mongoid::Errors::InvalidQuery","httpStatus":null,"severity":"error","filePath":"lib/mongoid/criteria/queryable/storable.rb","lineNumber":110,"sourceCode":"        # Such simplification is also expected to have already been performed\n        # by the upstream code.\n        #\n        # This method mutates the receiver.\n        #\n        # @param [ String ] operator The operator to add.\n        # @param [ Array<Hash> ] op_expr Operator value to add.\n        #\n        # @return [ Storable ] self.\n        def add_logical_operator_expression(operator, op_expr)\n          raise ArgumentError, \"Operator must be a string: #{operator}\" unless operator.is_a?(String)\n\n          unless %w[$and $nor $or].include?(operator)\n            raise ArgumentError,\n                  \"This method only handles logical operators ($and, $nor, $or). Operator given: #{operator}\"\n          end\n\n          unless op_expr.is_a?(Array)\n            raise Errors::InvalidQuery, \"#{operator} argument must be an array: #{Errors::InvalidQuery.truncate_expr(op_expr)}\"\n          end\n\n          if selector.length == 1 && selector.keys.first == operator\n            new_value = selector.values.first + op_expr\n            selector.store(operator, new_value)\n          elsif operator == '$and' || selector.empty?\n            # $and can always be added to top level and it will be combined\n            # with whatever other conditions exist.\n            if current_value = selector[operator]\n              new_value = current_value + op_expr\n              selector.store(operator, new_value)\n            else\n              selector.store(operator, op_expr)\n            end\n          elsif selector[operator]\n            # Other operators need to be added separately\n            add_logical_operator_expression('$and', [ { operator => op_expr } ])\n          else","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/mongodb/mongoid/blob/0da0e23d71adfbad31128c18e5e2c8c301c6f7c4/lib/mongoid/criteria/queryable/storable.rb#L92-L128","documentation":"Error \"#{operator} argument must be an array: #{Errors::InvalidQuery.truncate_expr(op_expr)}\" thrown in mongodb/mongoid.","triggerScenarios":"Thrown at lib/mongoid/criteria/queryable/storable.rb:110 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0da0e23d71adfbad31128c18e5e2c8c301c6f7c4","analyzedAt":"2026-08-23T06:25:47.656Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}