Registry / database / drop-mongodb-collections

drop-mongodb-collections

JSON →
library2.0.0jsnpmunverified

A utility to drop all non-system collections from a MongoDB database. Version 2.0.0 is stable, with infrequent releases. It is designed specifically for test setup/teardown, accepting a MongoDB URI and returning a cleanup function. Unlike generic drop-database tools, it preserves system collections and integrates easily with Mocha's beforeEach.

npm install drop-mongodb-collections
INSTALL
IMPORT
SIG · DROP-MONGODB-COLLE
D
drop-mongodb-collections
databasejavascriptv2.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import dropMongoDbCollections from 'drop-mongodb-collections';
const dropMongoDbCollections = require('drop-mongodb-collections');
ESM export since v2.0.0; CJS require no longer works.
dropMongoDbCollections as function
const cleanup = dropMongoDbCollections('mongodb://localhost/tests');
dropMongoDbCollections('mongodb://localhost/tests')();
Function returns a cleanup function; do not call twice.
Type import (TypeScript)
import type { DropMongoDbCollections } from 'drop-mongodb-collections';
const { DropMongoDbCollections } = require('drop-mongodb-collections');
Type-only import for TypeScript users; lib ships with types.

Shows ESM import, factory usage with env URI, and Mocha integration.

import dropMongoDbCollections from 'drop-mongodb-collections'; const cleanup = dropMongoDbCollections(process.env.MONGO_URI ?? 'mongodb://localhost/test'); // In Mocha beforeEach(cleanup); // Or manually await cleanup();
Debug
Known issues
breakingv2.0.0 dropped CommonJS support; package is now ESM-only.
fix
Use ESM import syntax or pin to v1.x if CJS required.
affects: >=2.0.0
gotchaFunction returns a cleanup function; calling dropMongoDbCollections() multiple times creates separate instances.
fix
Store return value and reuse it.
affects: *
deprecatedv1.x used callback style; v2.0.0 returns promise.
fix
Upgrade to v2 and use await or .then.
affects: <2.0.0
Errors
Common errors & fixes
TypeError: dropMongoDbCollections is not a function
Using require() with ESM-only v2 package.
fix
Use import instead, or downgrade to v1.
MongoError: not authorized on admin to execute command
User does not have dropDatabase privileges.
fix
Grant dropDatabase role to the MongoDB user.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
mongodbrequiredpeer dependency for MongoDB driver
Agent activity
12 hits · last 30 days
node
10
Resources
drop-mongodb-collections — npm install drop-mongodb-collections · libregistry