{"record":{"id":"1f382c09bc4305c2","repo":"mongodb/laravel-mongodb","slug":"this-method-is-not-supported-by-mongodb","errorCode":null,"errorMessage":"This method is not supported by MongoDB","messagePattern":"This method is not supported by MongoDB","errorType":"exception","errorClass":"BadMethodCallException","httpStatus":null,"severity":"error","filePath":"src/Query/Builder.php","lineNumber":1925,"sourceCode":"    /** @internal This method is not supported by MongoDB. */\n    #[Override]\n    public function toSql()\n    {\n        throw new BadMethodCallException('This method is not supported by MongoDB. Try \"toMql()\" instead.');\n    }\n\n    /** @internal This method is not supported by MongoDB. */\n    #[Override]\n    public function toRawSql()\n    {\n        throw new BadMethodCallException('This method is not supported by MongoDB. Try \"toMql()\" instead.');\n    }\n\n    /** @internal This method is not supported by MongoDB. */\n    #[Override]\n    public function whereColumn($first, $operator = null, $second = null, $boolean = 'and')\n    {\n        throw new BadMethodCallException('This method is not supported by MongoDB');\n    }\n\n    /** @internal This method is not supported by MongoDB. */\n    #[Override]\n    public function whereFullText($columns, $value, array $options = [], $boolean = 'and')\n    {\n        throw new BadMethodCallException('This method is not supported by MongoDB');\n    }\n\n    /** @internal This method is not supported by MongoDB. */\n    #[Override]\n    public function groupByRaw($sql, array $bindings = [])\n    {\n        throw new BadMethodCallException('This method is not supported by MongoDB');\n    }\n\n    /** @internal This method is not supported by MongoDB. */\n    #[Override]","sourceCodeStart":1907,"sourceCodeEnd":1943,"githubUrl":"https://github.com/mongodb/laravel-mongodb/blob/0634653039468ceb0268a69192bdac64469ed043/src/Query/Builder.php#L1907-L1943","documentation":"whereColumn() compares one database column against another in SQL (WHERE a = b). MongoDB has no direct equivalent for arbitrary column-to-column comparison in the Laravel builder, so the override throws BadMethodCallException. Such comparisons must be expressed via aggregation pipelines or $expr if truly needed.","triggerScenarios":"Calling ->whereColumn('a', 'b') (any operator variant) on a MongoDB query builder.","commonSituations":"Porting SQL codebases that compare columns (e.g. whereColumn('deactivated_at', '>', 'last_seen_at')) to MongoDB; ORM-agnostic query code that uses column comparisons.","solutions":["Rewrite the condition comparing two fields using whereRaw-style MQL or the library's supported operators (e.g. ->where('deactivated_at', '>', new MongoDB\\BSON\\UTCDateTime(...)) only works for values, so prefer an aggregation $expr via raw filter)","Compute one side in PHP and use a regular where() with a concrete value if feasible","Use Model::raw() / aggregation pipeline for field-vs-field comparisons","Restructure the document schema so the comparison is against a stored value"],"exampleFix":"// before\nUser::whereColumn('updated_at', '>', 'created_at')->get();\n\n// after\nUser::raw(function ($c) {\n    return $c->aggregate([\n        ['$match' => ['$expr' => ['$gt' => ['$updated_at', '$created_at']]]],\n    ]);\n});","handlingStrategy":"validation","validationCode":"if ($builder instanceof MongoDB\\Laravel\\Query\\Builder) { /* use aggregation $expr instead of whereColumn */ }","typeGuard":null,"tryCatchPattern":"try { $q->whereColumn('a', 'b'); } catch (\\BadMethodCallException $e) { $q = Model::raw(...$expr pipeline...); }","preventionTips":["Replace column-to-column comparisons with $expr aggregations when on MongoDB","Compute comparisons in PHP where the dataset allows","Keep driver-specific query code in separate repository methods"],"tags":["mongodb","laravel","query-builder","unsupported-method"],"backgroundTag":"unsupported-operation","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"}