diff --git a/lib/Configuration.ts b/lib/Configuration.ts index ec6ebdf..7b642ad 100644 --- a/lib/Configuration.ts +++ b/lib/Configuration.ts @@ -8,118 +8,7 @@ export interface Configuration { username?: string; password?: string; - options?: ConnectionOptions; + options?: MongoDB.MongoClientOptions; [key:string]: any; -} - -export interface ConnectionOptions { - db?: DatabaseLevelConnectionOptions; - server?: ServerLevelConnectionOptions; - replset?: ReplicasetLevelConnectionOptions; - mongos?: MongosLevelConnectionOptions; -} - -export interface DatabaseLevelConnectionOptions { - /** - * The write concern for the operation where < 1 is no acknowledgment of write and w >= 1 or w = ‘majority’ acknowledges the write - */ - w?: string | number; - - /** - * Set the timeout for waiting for write concern to finish (combines with w option) - */ - wtimeout?: number; - - /** - * Write waits for fsync before returning - */ - fsync?: boolean; - - /** - * Write waits for journal sync before returning - */ - j?: boolean; - - /** - * The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). - */ - readPreference?: string; - - /** - * The tags object {‘loc’:‘ny’} used with the readPreference. - */ - readPreferenceTags?: any; - - /** - * Use c++ bson parser. - */ - native_parser?: boolean; - - /** - * Force server to create _id fields instead of client. - */ - forceServerObjectId?: boolean; - - /** - * Object overriding the basic ObjectID primary key generation. - */ - pkFactory?: any; - - /** - * Serialize functions. - */ - serializeFunctions?: boolean; - - /** - * Perform operations using raw bson buffers. - */ - raw?: boolean; - - /** - * Number of milliseconds between retries. - */ - retryMiliseconds?: number; - - /** - * Number of retries off connection. - */ - numberOfRetries?: number; - - /** - * Sets a cap on how many operations the driver will buffer up before giving up on getting a working connection, default is -1 which is unlimited. - */ - bufferMaxEntries?: number; -} - -export interface ServerLevelConnectionOptions extends BasicConnectionOptions { - autoReconnect?: boolean; -} - -export interface ReplicasetLevelConnectionOptions extends MongosLevelConnectionOptions { - replicaSet?: string; - connectWithNoPrimary?: boolean; -} - -export interface MongosLevelConnectionOptions extends BasicConnectionOptions { - ha?: boolean; - haInterval?: number; - secondaryAcceptableLatencyMS?: number; -} - -export interface BasicConnectionOptions { - poolSize?: number; - ssl?: boolean; - sslValidate?: boolean; - sslCA?: Buffer[] | string[]; - sslCert?: Buffer | string; - sslKey?: Buffer | string; - sslPass?: Buffer | string; - - socketOptions?: { - noDelay?: boolean; - keepAlive?: number; - connectTimeoutMS?: number; - socketTimeoutMS?: number; - } } \ No newline at end of file diff --git a/lib/Core.ts b/lib/Core.ts index accd409..9abf49d 100644 --- a/lib/Core.ts +++ b/lib/Core.ts @@ -49,7 +49,7 @@ export class Core { } } - private mongoConnectAsyc = Bluebird.promisify(MongoDB.MongoClient.connect); + private mongoConnectAsyc = Bluebird.promisify(MongoDB.MongoClient.connect); private _plugins: Plugin[] = []; private _url: string; @@ -165,7 +165,7 @@ export class Core { return Bluebird.resolve().then(() => { if (this._connection) return this._connection; if (this._connectPromise) return this._connectPromise; - return this._connectPromise = this.mongoConnectAsyc(this.url, this._config && this._config.options); + return this._connectPromise = this.mongoConnectAsyc(this.url, this._config && this._config.options || {}); }).then((db: MongoDB.Db) => { return this.onConnecting(db); }).then(db => {