Skip to content

Collection and Client getters

Utility functions for global access to Collections and MongoClient.

getCollection(name [, options]) => Collection

typescript
getCollection(name [, options]) => Collection

Get a new instance of a collection. Uses default database determined from the connection string. See official driver documentation for valid options.

typescript
import { getCollection } from 'mongodash'; 
const myCollection = getCollection('myCollectionName');

The method just shortens getMongoClient().db().collection('myCollectionName').

getMongoClient() => MongoClient

typescript
getMongoClient() => MongoClient

Returns the global instance of MongoClient. See official driver documentation for documentation of MongoClient.

typescript
import { getMongoClient } from 'mongodash'; 
const mongoClient = getMongoClient();