{"id":"e065a48e36a86cf8","repo":"typeorm/typeorm","slug":"database-drop-queries-are-not-supported-by-mongodb","errorCode":null,"errorMessage":"Database drop queries are not supported by MongoDB driver.","messagePattern":"Database drop queries are not supported by MongoDB driver\\.","errorType":"exception","errorClass":"TypeORMError","httpStatus":null,"severity":"error","filePath":"src/driver/mongodb/MongoQueryRunner.ts","lineNumber":865,"sourceCode":"    /**\n     * Creates a database if it's not created.\n     *\n     * @param database\n     */\n    async createDatabase(database: string): Promise<void> {\n        throw new TypeORMError(\n            `Database create queries are not supported by MongoDB driver.`,\n        )\n    }\n\n    /**\n     * Drops database.\n     *\n     * @param database\n     * @param ifExists\n     */\n    async dropDatabase(database: string, ifExists?: boolean): Promise<void> {\n        throw new TypeORMError(\n            `Database drop queries are not supported by MongoDB driver.`,\n        )\n    }\n\n    /**\n     * Creates a new table schema.\n     *\n     * @param schemaPath\n     * @param ifNotExists\n     */\n    async createSchema(\n        schemaPath: string,\n        ifNotExists?: boolean,\n    ): Promise<void> {\n        throw new TypeORMError(\n            `Schema create queries are not supported by MongoDB driver.`,\n        )\n    }","sourceCodeStart":847,"sourceCodeEnd":883,"githubUrl":"https://github.com/typeorm/typeorm/blob/04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96/src/driver/mongodb/MongoQueryRunner.ts#L847-L883","documentation":"MongoQueryRunner.dropDatabase() (src/driver/mongodb/MongoQueryRunner.ts:864) throws TypeORMError. Although MongoDB can drop a database, TypeORM's MongoQueryRunner deliberately does not expose this destructive relational API; the method is an unsupported stub that always throws.","triggerScenarios":"Calling `queryRunner.dropDatabase('mydb')` (often in migration `down()` or test teardown) against a MongoDB DataSource.","commonSituations":"Test-suite cleanup routines shared across drivers; migration down() methods that revert by dropping the DB.","solutions":["Drop via the MongoDB driver directly: `dataSource.mongoManager.connectionClient.db('mydb').dropDatabase()`.","Prefer dropping individual collections over the whole database for safer teardown.","Branch teardown by driver type and route MongoDB cleanup through the mongo client."],"exampleFix":"// before\nawait queryRunner.dropDatabase('mydb');\n// after\nawait dataSource.mongoManager\n  .connectionClient.db('mydb').dropDatabase();","handlingStrategy":"validation","validationCode":"if (dataSource.options.type === 'mongodb') {\n  await dataSource.mongoManager.connectionClient.db('mydb').dropDatabase();\n} else {\n  await queryRunner.dropDatabase('mydb');\n}","typeGuard":"const isMongoRunner = (qr: any): boolean =>\n  qr?.constructor?.name === 'MongoQueryRunner';","tryCatchPattern":"try {\n  await queryRunner.dropDatabase('mydb');\n} catch (e) {\n  if (e instanceof TypeORMError && /not supported by MongoDB/.test(e.message)) {\n    await dataSource.mongoManager.connectionClient.db('mydb').dropDatabase();\n  } else throw e;\n}","preventionTips":["Route DB drops through the mongo client for MongoDB.","Prefer dropping collections to dropping whole DBs in tests.","Branch teardown helpers by driver type."],"tags":["mongodb","typeorm","query-runner","unsupported-operation","database"],"analyzedSha":"04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96","analyzedAt":"2026-08-03T18:27:32.281Z","schemaVersion":2}