{"id":42654,"library":"drop-mongodb-collections","title":"drop-mongodb-collections","description":"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.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/saintedlama/drop-mongodb-collections","tags":["javascript","mongodb","collections","test","testing"],"install":[{"cmd":"npm install drop-mongodb-collections","lang":"bash","label":"npm"},{"cmd":"yarn add drop-mongodb-collections","lang":"bash","label":"yarn"},{"cmd":"pnpm add drop-mongodb-collections","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency for MongoDB driver","package":"mongodb","optional":false}],"imports":[{"note":"ESM export since v2.0.0; CJS require no longer works.","wrong":"const dropMongoDbCollections = require('drop-mongodb-collections');","symbol":"default","correct":"import dropMongoDbCollections from 'drop-mongodb-collections';"},{"note":"Function returns a cleanup function; do not call twice.","wrong":"dropMongoDbCollections('mongodb://localhost/tests')();","symbol":"dropMongoDbCollections as function","correct":"const cleanup = dropMongoDbCollections('mongodb://localhost/tests');"},{"note":"Type-only import for TypeScript users; lib ships with types.","wrong":"const { DropMongoDbCollections } = require('drop-mongodb-collections');","symbol":"Type import (TypeScript)","correct":"import type { DropMongoDbCollections } from 'drop-mongodb-collections';"}],"quickstart":{"code":"import dropMongoDbCollections from 'drop-mongodb-collections';\n\nconst cleanup = dropMongoDbCollections(process.env.MONGO_URI ?? 'mongodb://localhost/test');\n\n// In Mocha\nbeforeEach(cleanup);\n\n// Or manually\nawait cleanup();","lang":"typescript","description":"Shows ESM import, factory usage with env URI, and Mocha integration."},"warnings":[{"fix":"Use ESM import syntax or pin to v1.x if CJS required.","message":"v2.0.0 dropped CommonJS support; package is now ESM-only.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Store return value and reuse it.","message":"Function returns a cleanup function; calling dropMongoDbCollections() multiple times creates separate instances.","severity":"gotcha","affected_versions":"*"},{"fix":"Upgrade to v2 and use await or .then.","message":"v1.x used callback style; v2.0.0 returns promise.","severity":"deprecated","affected_versions":"<2.0.0"}],"env_vars":null,"search_vec":"'2.0.0':19 'accept':32 'beforeeach':57 'cleanup':39 'collect':4,13,50,60 'databas':17,45 'design':27 'drop':2,8,44 'drop-databas':43 'drop-mongodb-collect':1 'easili':53 'function':40 'generic':42 'infrequ':23 'integr':52 'javascript':58 'mocha':55 'mongodb':3,16,34,59 'non':11 'non-system':10 'preserv':48 'releas':24 'return':37 'setup/teardown':31 'specif':28 'stabl':21 'system':12,49 'test':30,61,62 'tool':46 'unlik':41 'uri':35 'util':6 'version':18","created_at":"2026-06-05T16:56:00.902263+00:00","updated_at":"2026-06-05T16:56:00.902263+00:00","problems":[{"fix":"Use import instead, or downgrade to v1.","cause":"Using require() with ESM-only v2 package.","error":"TypeError: dropMongoDbCollections is not a function"},{"fix":"Grant dropDatabase role to the MongoDB user.","cause":"User does not have dropDatabase privileges.","error":"MongoError: not authorized on admin to execute command"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/saintedlama/drop-mongodb-collections#readme","github":"https://github.com/saintedlama/drop-mongodb-collections","docs":null,"changelog":null,"pypi":null,"npm":"drop-mongodb-collections","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database","testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}