Registry / database / feathers-mongodb-management-ts

feathers-mongodb-management-ts

JSON →
library2.3.2jsnpmunverified

MongoDB management helpers for Feathers v5 (Koa) applications, written in TypeScript. Version 2.3.2 provides utilities for database administration tasks such as creating indexes, managing collections, and running migrations against a MongoDB instance via Feathers services. It leverages the official MongoDB Node.js driver and Feathers' hook and service patterns. Released regularly, it is designed specifically for Feathers v5 and TypeScript users, offering type-safe methods compared to generic MongoDB management scripts. Key differentiators: tight integration with Feathers 5's dependency injection and hooks, full TypeScript support, and focus on common admin operations.

npm install feathers-mongodb-management-ts
INSTALL
IMPORT
SIG · FEATHERS-MONGODB-M
F
feathers-mongodb-management-ts
databasejavascriptv2.3.2
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.

ManagementService
✓ import { ManagementService } from 'feathers-mongodb-management-ts'
✗ const ManagementService = require('feathers-mongodb-management-ts').ManagementService
ESM default since v2. Use named import; CJS require must use .default or destructure.
createIndexes
✓ import { createIndexes } from 'feathers-mongodb-management-ts'
✗ import createIndexes from 'feathers-mongodb-management-ts'
Function is exported as a named export, not default. Wrong import yields undefined.
ManagementType
✓ import type { ManagementType } from 'feathers-mongodb-management-ts'
✗ import { ManagementType } from 'feathers-mongodb-management-ts'
ManagementType is a TypeScript type, should be imported with `type` to avoid runtime errors in TS.

Registers the ManagementService and uses createIndexes to add indexes to the 'users' collection. Assumes a Feathers v5 app with MongoDB connection.

import { feathers } from '@feathersjs/feathers'; import { ManagementService, createIndexes } from 'feathers-mongodb-management-ts'; const app = feathers(); // Register the management service app.use('management', new ManagementService({ db: 'mongodb://localhost:27017/myapp' })); // Create indexes for a collection const indexes = [ { key: { email: 1 }, unique: true }, { key: { createdAt: -1 }, background: true } ]; async function run() { const service = app.service('management'); await createIndexes(service, 'users', indexes); console.log('Indexes created'); } run().catch(console.error);
Debug
Known issues
breakingManagementService constructor now requires options object with `db` property; previous versions accepted a connection string directly.
fix
Update to `new ManagementService({ db: connectionString })` and pass any additional options like `options`.
affects: <2.0.0
breakingAll functions are now ESM-only; CommonJS `require` still works via `.default` but will be removed in v3.
fix
Use ES import syntax or `const pkg = require('feathers-mongodb-management-ts').default`.
affects: >=2.0.0
deprecated`dropCollection` method is deprecated in favor of `removeService` service method.
fix
Use `app.service('management').remove('collectionName')` instead of `dropCollection(service, 'collectionName')`.
affects: >=2.0.0
gotchaThe package does not handle MongoDB connection lifecycle; you must provide a connected client or connection string to the constructor. Reconnection logic is not included.
fix
Ensure your connection is established before calling any management methods, or pass a connected `MongoClient` instance via `{ client }`.
affects: *
gotchaIndex creation in the background (`background: true`) is ignored in MongoDB versions 4.2+. The option is silently ignored but still accepted.
fix
Remove `background: true` for MongoDB >=4.2 or rely on the driver's default behavior.
affects: *
Errors
Common errors & fixes
TypeError: (0 , feathers_mongodb_management_ts.createIndexes) is not a function
Wrong import syntax; using default import instead of named import.
fix
Use `import { createIndexes } from 'feathers-mongodb-management-ts'`.
Error: Invalid schema, expected `db` to be a string or an object
ManagementService constructor called without `db` property (e.g., `new ManagementService('str')` instead of `new ManagementService({ db: 'str' })`).
fix
Pass an object with `db` key: `new ManagementService({ db: 'mongodb://...' })`.
Cannot find name 'ManagementType'. Did you mean 'ManagementService'?
Importing ManagementType without specifying `type` keyword in TypeScript, or it's used in value position.
fix
Use `import type { ManagementType } from '...'` and ensure it's used as a type only.
Upgrade
Version history
2.3.2latest on npm
Audit
Dependencies
@feathersjs/feathersoptionalPeer dependency: required for Feathers application and service interfaces
Agent activity
7 hits · last 30 days
node
6
Resources
feathers-mongodb-management-ts — npm install feathers-mongodb-management-ts · libregistry