UNPKG

@onesy/mongo

Version:

Utils for easier using of mongodb library.

48 lines (47 loc) 1.5 kB
import * as mongodb from 'mongodb'; import OnesyLog from '@onesy/log'; import { IOnesyLogOptions } from '@onesy/log/OnesyLog'; import OnesySubscription from '@onesy/subscription'; export interface IMongoCollectionIndex { name: string; indexes: Array<{ keys: mongodb.IndexSpecification; options?: mongodb.CreateIndexesOptions; }>; } export interface IMongoOptions { name?: string; uri?: string; log_options?: IOnesyLogOptions; indexes?: IMongoCollectionIndex[]; reconnectInterval?: number; maxReconnectAttempts?: number; } export interface IDefaults { aggregateOptions?: mongodb.AggregateOptions; limitCount?: number; } export declare const mongoOptionsDefault: IMongoOptions; export declare class Mongo { db: mongodb.Db; connected: boolean; client: mongodb.MongoClient; onesyLog: OnesyLog; private options_; collections: Array<mongodb.CollectionInfo>; subscription: OnesySubscription<any>; indexed: boolean; retrying: boolean; static defaults: IDefaults; get options(): IMongoOptions; set options(options: IMongoOptions); constructor(options?: IMongoOptions); createIndexes(): Promise<any>; get connection(): Promise<mongodb.Db> | Error; get disconnect(): Promise<void>; getCollections(refetch?: boolean): Promise<Array<mongodb.CollectionInfo>>; reset(name: string): Promise<void>; private connect; private setupConnectionListeners; } export default Mongo;