mongodb-memory-server
Version:
In-memory MongoDB Server. Designed with testing in mind, the server will allow you to connect your favourite ODM or client library to the MongoDB Server and run integration tests isolated from each other.
30 lines (26 loc) • 730 B
Flow
// @flow
import uuid from 'uuid/v4';
import type { ReplStatusResultT } from '../types';
/**
* Returns a database name string.
* @param {string} dbName
*/
export function generateDbName(dbName?: string): string {
return dbName || uuid();
}
/**
* Extracts the host and port information from a mongodb URI string.
* @param {string} uri mongodb URI
*/
export function getHost(uri: string): string {
return uri.replace('mongodb://', '').replace(/\/.*/, '');
}
/**
* Returns replica set status result.
* @param {any} db db instance
*/
export async function getReplStatus(db: any): Promise<ReplStatusResultT> {
const status = await db.command({ replSetGetStatus: 1 });
return status;
}
export default generateDbName;