Skip to content

Initialization

Installation

bash
npm install mongodash

mongodash.init(options) => Promise

Initializes the mongodash library. This method must be called before using any other features.

typescript
import mongodash from 'mongodash';

// Initialize with connection string
await mongodash.init({
    uri: 'mongodb://localhost:27017/my-app',
    // ...other options
});

// OR initialize with existing MongoClient
await mongodash.init({
    mongoClient: myExistingClient,
    // ...other options
});

Options Reference

Connection Options

OptionTypeDescription
uristringRequired (if mongoClient is not provided). The MongoDB connection string. mongodash will connect automatically.
mongoClientMongoClientRequired (if uri is not provided). An existing, connected MongoClient instance.
clientOptionsMongoClientOptionsOptional. Used only when uri is provided. Options passed to the MongoDB driver.

General Options

OptionTypeDescription
globalsCollectionstring | CollectionName of the collection used for distributed locking and coordination. Mongodash uses a fixed set of documents identified by unique derived _ids, so it has a minimal storage footprint and doesn't pollute the collection. Default: _mongodash_globals.
onError(err: Error) => voidGlobal error handler. Default: console.error.
onInfo(info: Info) => voidGlobal info/debug handler. Default: console.info.

Cron Tasks Options

See Cron Tasks for feature-specific options (e.g. runCronTasks, cronExpressionParserOptions, etc).

Reactive Tasks Options

See Reactive Tasks for feature-specific options (e.g. concurrency, monitoring, etc).

Testing Options

OptionTypeDescription
collectionFactoryFunctionInternal. Used for injecting mock collections during testing.