typeorm/typeorm · error · TypeORMError
Database drop queries are not supported by MongoDB driver.
Error message
Database drop queries are not supported by MongoDB driver.
What it means
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.
Source
Thrown at src/driver/mongodb/MongoQueryRunner.ts:865
/**
* Creates a database if it's not created.
*
* @param database
*/
async createDatabase(database: string): Promise<void> {
throw new TypeORMError(
`Database create queries are not supported by MongoDB driver.`,
)
}
/**
* Drops database.
*
* @param database
* @param ifExists
*/
async dropDatabase(database: string, ifExists?: boolean): Promise<void> {
throw new TypeORMError(
`Database drop queries are not supported by MongoDB driver.`,
)
}
/**
* Creates a new table schema.
*
* @param schemaPath
* @param ifNotExists
*/
async createSchema(
schemaPath: string,
ifNotExists?: boolean,
): Promise<void> {
throw new TypeORMError(
`Schema create queries are not supported by MongoDB driver.`,
)
}View on GitHub (pinned to 04ff4daedc)
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.
Example fix
// before
await queryRunner.dropDatabase('mydb');
// after
await dataSource.mongoManager
.connectionClient.db('mydb').dropDatabase(); Defensive patterns
Strategy: validation
Validate before calling
if (dataSource.options.type === 'mongodb') {
await dataSource.mongoManager.connectionClient.db('mydb').dropDatabase();
} else {
await queryRunner.dropDatabase('mydb');
} Type guard
const isMongoRunner = (qr: any): boolean => qr?.constructor?.name === 'MongoQueryRunner';
Try / catch
try {
await queryRunner.dropDatabase('mydb');
} catch (e) {
if (e instanceof TypeORMError && /not supported by MongoDB/.test(e.message)) {
await dataSource.mongoManager.connectionClient.db('mydb').dropDatabase();
} else throw e;
} Prevention
- Route DB drops through the mongo client for MongoDB.
- Prefer dropping collections to dropping whole DBs in tests.
- Branch teardown helpers by driver type.
When it happens
Trigger: Calling `queryRunner.dropDatabase('mydb')` (often in migration `down()` or test teardown) against a MongoDB DataSource.
Common situations: Test-suite cleanup routines shared across drivers; migration down() methods that revert by dropping the DB.
Related errors
- Database create queries are not supported by MongoDB driver.
- Check schema queries are not supported by MongoDB driver.
- Schema create queries are not supported by MongoDB driver.
- Schema drop queries are not supported by MongoDB driver.
- Executing SQL query is not supported by MongoDB driver.
AI-assisted analysis of typeorm/typeorm@04ff4daedc (2026-08-03).
Data as JSON: /data/errors/e065a48e36a86cf8.json.
Report an issue: GitHub.