{"record":{"id":"84af38ced2ba3aef","repo":"n8n-io/n8n","slug":"tree-repositories-are-not-supported-in-driver-op","errorCode":null,"errorMessage":"Tree repositories are not supported in ${driver.options.type} driver.","messagePattern":"Tree repositories are not supported in (.+?) driver\\.","errorType":"exception","errorClass":"TreeRepositoryNotSupportedError","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/entity-manager/EntityManager.ts","lineNumber":1254,"sourceCode":"\n\t\t// if repository was not found then create it, store its instance and return it\n\t\tconst newRepository = new Repository<any>(target, this, this.queryRunner);\n\t\tthis.repositories.set(target, newRepository);\n\t\treturn newRepository;\n\t}\n\n\t/**\n\t * Gets tree repository for the given entity class or name.\n\t * If single database connection mode is used, then repository is obtained from the\n\t * repository aggregator, where each repository is individually created for this entity manager.\n\t * When single database connection is not used, repository is being obtained from the connection.\n\t */\n\tgetTreeRepository<Entity extends ObjectLiteral>(\n\t\ttarget: EntityTarget<Entity>,\n\t): TreeRepository<Entity> {\n\t\t// tree tables aren't supported by some drivers (mongodb)\n\t\tif (this.connection.driver.treeSupport === false)\n\t\t\tthrow new TreeRepositoryNotSupportedError(this.connection.driver);\n\n\t\t// find already created repository instance and return it if found\n\t\tconst repository = this.treeRepositories.find((repository) => repository.target === target);\n\t\tif (repository) return repository;\n\n\t\t// check if repository is real tree repository\n\t\tconst newRepository = new TreeRepository(target, this, this.queryRunner);\n\t\tthis.treeRepositories.push(newRepository);\n\t\treturn newRepository;\n\t}\n\n\t/**\n\t * Creates a new repository instance out of a given Repository and\n\t * sets current EntityManager instance to it. Used to work with custom repositories\n\t * in transactions.\n\t */\n\twithRepository<Entity extends ObjectLiteral, R extends Repository<any>>(\n\t\trepository: R & Repository<Entity>,","sourceCodeStart":1236,"sourceCodeEnd":1272,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/entity-manager/EntityManager.ts#L1236-L1272","documentation":"EntityManager.getTreeRepository checks the active driver's `treeSupport` flag (false for MongoDB and any driver without closure-table / nested-set support). When treeSupport is false, it throws TreeRepositoryNotSupportedError naming the driver type. Tree repositories require SQL features (CTEs/closure tables) that some drivers cannot provide.","triggerScenarios":"Configuring a @TreeParen/TreeChildren/TreeLevelColumn entity against MongoDB; calling `manager.getTreeRepository(Category)` while connected to a non-tree-supporting driver; mixing a tree-decorated entity into a multi-DB project where one connection is MongoDB; migrating from SQL to Mongo without removing tree decorators.","commonSituations":"Switching DB engines without auditing entity decorators; copy-pasting a tree-structured entity from a SQL project into a Mongo project; testing against Mongo while production runs on Postgres.","solutions":["Use a tree-supporting driver (Postgres, MySQL, SQLite, MSSQL) for entities decorated with @Tree/@TreeChildren/@TreeParent.","If you must stay on MongoDB, model the hierarchy manually (parent references + recursive aggregation) and stop using the TreeRepository API.","Audit `@Tree(` decorators across the codebase before changing the configured driver."],"exampleFix":"// before - tree entity used against MongoDB\n@Entity()\n@Tree('closure-table')\nclass Category { @TreeChildren() children?: Category[]; }\n// DataSource type: 'mongodb'\n\n// after - use Postgres, or drop tree decorators on Mongo\n// Option A: switch datasource to a tree-supporting driver\nconst ds = new DataSource({ type: 'postgres', ... });\n// Option B: keep Mongo, remove @Tree and model parent refs manually","handlingStrategy":"validation","validationCode":"function assertTreeSupported(driver: import('@n8n/typeorm').Driver): void {\n  if ((driver as any).treeSupport === false) {\n    throw new Error(`Driver ${driver.options.type} does not support tree repositories`);\n  }\n}\nassertTreeSupported(connection.driver);\nawait manager.getTreeRepository(Category);","typeGuard":"function driverSupportsTrees(driver: import('@n8n/typeorm').Driver): boolean {\n  return (driver as any).treeSupport !== false;\n}","tryCatchPattern":null,"preventionTips":["Do not use @Tree/@TreeChildren/@TreeParent on MongoDB entities.","Before switching DB engines, grep for @Tree decorators.","Model hierarchies manually (parent FK + recursive query) on non-tree drivers.","Keep tree-decorated entities in their own connection if multi-DB."],"tags":["typeorm","tree","mongodb","driver-support"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}