{"record":{"id":"4c01225e128879d1","repo":"mongodb/laravel-mongodb","slug":"between-values-must-be-a-list-with-exactly-two-elements-min","errorCode":null,"errorMessage":"Between $values must be a list with exactly two elements: [min, max]","messagePattern":"Between \\$values must be a list with exactly two elements: \\[min, max\\]","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Query/Builder.php","lineNumber":734,"sourceCode":"        foreach ($toUnset as $column) {\n            unset($orders[$column]);\n        }\n\n        return $orders;\n    }\n\n    /** @inheritdoc */\n    #[Override]\n    public function whereBetween($column, iterable $values, $boolean = 'and', $not = false)\n    {\n        $type = 'between';\n\n        if ($values instanceof Collection) {\n            $values = $values->all();\n        }\n\n        if (is_array($values) && (! array_is_list($values) || count($values) !== 2)) {\n            throw new InvalidArgumentException('Between $values must be a list with exactly two elements: [min, max]');\n        }\n\n        $this->wheres[] = [\n            'column'  => $column,\n            'type'    => $type,\n            'boolean' => $boolean,\n            'values'  => $values,\n            'not'     => $not,\n        ];\n\n        return $this;\n    }\n\n    /** @inheritdoc */\n    #[Override]\n    public function insert(array $values)\n    {\n        // Allow empty insert batch for consistency with Eloquent SQL","sourceCodeStart":716,"sourceCodeEnd":752,"githubUrl":"https://github.com/mongodb/laravel-mongodb/blob/0634653039468ceb0268a69192bdac64469ed043/src/Query/Builder.php#L716-L752","documentation":"Thrown by whereBetween()/orWhereBetween() when the $values argument is not a flat list of exactly two elements. The MongoDB builder requires the literal [min, max] shape to build a {$gte: min, $lte: max} range filter; keyed arrays, arrays of 0/1/3+ elements, or non-list inputs are rejected.","triggerScenarios":"Calling ->whereBetween('age', ['min' => 18, 'max' => 65]) (string keys, not a list), ->whereBetween('age', [18, 65, 99]) (3 elements), ->whereBetween('age', []) (0 elements), or passing a Collection whose ->all() is not a 2-element list.","commonSituations":"Building the range dynamically from config or request input where optional bounds result in fewer/more elements; PHP arrays with non-sequential keys after unset(); devs used to Laravel's SQL builder being lenient about array shape.","solutions":["Pass a numerically-indexed array with exactly two values in [min, max] order, e.g. ->whereBetween('price', [10, 100]).","Use array_values($bounds) to strip string/associative keys before calling.","Ensure bounds-collection logic always yields exactly two entries (check count($values) === 2 before calling).","If only one bound is needed, use ->where('price', '>=', 10) or ->where('price', '<=', 100) instead."],"exampleFix":"// before\n$bounds = ['min' => 10, 'max' => 100];\n$query->whereBetween('price', $bounds);\n// after\n$bounds = array_values(['min' => 10, 'max' => 100]); // [10, 100]\n$query->whereBetween('price', $bounds);","handlingStrategy":"validation","validationCode":"if (!is_array($values) || !array_is_list($values) || count($values) !== 2) {\n    throw new InvalidArgumentException('whereBetween expects [min, max]');\n}\n$query->whereBetween($column, $values);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always build ranges with array_values([min, max]).","Assert count === 2 in range-builder helpers.","Avoid keyed arrays for bounds."],"tags":["php","laravel-mongodb","argument-validation"],"backgroundTag":"invalid-argument-format","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"}