{"record":{"id":"3f048028af465c25","repo":"mongodb/laravel-mongodb","slug":"too-few-arguments-to-function-s-s-1-passed-and-at-least-2","errorCode":null,"errorMessage":"Too few arguments to function %s(%s), 1 passed and at least 2 expected when the 1st is not an array or a callable","messagePattern":"Too few arguments to function (.+?)\\((.+?)\\), 1 passed and at least 2 expected when the 1st is not an array or a callable","errorType":"exception","errorClass":"ArgumentCountError","httpStatus":null,"severity":"error","filePath":"src/Query/Builder.php","lineNumber":1310,"sourceCode":"        // Remove the leading $ from operators.\n        if (func_num_args() >= 3) {\n            $operator = &$params[1];\n\n            if (is_string($operator) && str_starts_with($operator, '$')) {\n                $operator = substr($operator, 1);\n            }\n\n            if ($operator === self::UNSAFE_FIELD_QUERY) {\n                $operator = '=';\n            } elseif ($operator === '=' && self::firstOperatorKey($params[2]) !== null) {\n                $this->throwIfIdLikeOperatorValue($params[0], $params[2]);\n\n                $params[2] = ['$eq' => $params[2]];\n            }\n        }\n\n        if (func_num_args() === 1 && ! is_array($column) && ! is_callable($column)) {\n            throw new ArgumentCountError(sprintf('Too few arguments to function %s(%s), 1 passed and at least 2 expected when the 1st is not an array or a callable', __METHOD__, var_export($column, true)));\n        }\n\n        if (is_float($column) || is_bool($column) || $column === null) {\n            throw new InvalidArgumentException(sprintf('First argument of %s must be a field path as \"string\". Got \"%s\"', __METHOD__, get_debug_type($column)));\n        }\n\n        return parent::where(...$params);\n    }\n\n    /** Array-of-wheres calls are marked so their generated \"=\" keeps building an operator document. */\n    #[Override]\n    protected function addArrayOfWheres($column, $boolean, $method = 'where')\n    {\n        return $this->whereNested(function ($query) use ($column, $method, $boolean) {\n            foreach ($column as $key => $value) {\n                if (is_numeric($key) && is_array($value)) {\n                    $query->{$method}(...array_values($value), boolean: $boolean);\n                } else {","sourceCodeStart":1292,"sourceCodeEnd":1328,"githubUrl":"https://github.com/mongodb/laravel-mongodb/blob/0634653039468ceb0268a69192bdac64469ed043/src/Query/Builder.php#L1292-L1328","documentation":"where() requires at least 2 arguments unless the first argument is an array of columns/conditions or a callable sub-query builder. A single non-array, non-callable argument is ambiguous and rejected with an ArgumentCountError naming the actual column value.","triggerScenarios":"->where('email') (no operator/value); ->where(null); typo'd call where the operator/value were dropped during refactoring; dynamic argument spreading where func_get_args produced one element.","commonSituations":"Refactoring leftovers; building conditions from arrays that turned out empty; misuse of where() intending ->whereNotNull().","solutions":["Provide the full triple: ->where('email', '=', $value) or shorthand ->where('email', $value).","If checking for null use ->whereNull('email') or ->where('email', '=', null) with explicit operator.","Guard dynamically-built calls: only call where() when count($args) >= 2 or is_array($args[0]).","Use ->where($conditions) with an array form for dynamic condition sets."],"exampleFix":"// before\n$query->where('status');\n// after\n$query->where('status', '=', 'active');","handlingStrategy":"type-guard","validationCode":"if (!is_array($column) && !is_callable($column) && func_num_args() < 2) {\n    throw new InvalidArgumentException('where() needs column + value');\n}","typeGuard":"function canCallWhere(mixed ...$args): bool {\n    return count($args) >= 2 || is_array($args[0] ?? null) || is_callable($args[0] ?? null);\n}","tryCatchPattern":null,"preventionTips":["Always write where($col, $value) or where($col, $op, $value).","Use whereNull()/whereNotNull() for null checks.","Guard dynamic-argument builders before dispatching."],"tags":["php","laravel-mongodb","argument-count"],"backgroundTag":"missing-required-argument","analyzedSha":"0634653039468ceb0268a69192bdac64469ed043","analyzedAt":"2026-09-15T02:56:37.067Z","contentChangedAt":"2026-09-15T02:56:37.067Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}