Add useNewUrlParser options to GridFSBucketAdapter (#5548)

* Add useNewUrlParser options to GridFSBucketAdapter

* allow overriding default
This commit is contained in:
Diamond Lewis
2019-05-01 00:44:10 -05:00
committed by GitHub
parent 057fc40c1d
commit 9594c4b59f
2 changed files with 19 additions and 8 deletions

View File

@@ -14,17 +14,22 @@ import defaults from '../../defaults';
export class GridFSBucketAdapter extends FilesAdapter { export class GridFSBucketAdapter extends FilesAdapter {
_databaseURI: string; _databaseURI: string;
_connectionPromise: Promise<Db>; _connectionPromise: Promise<Db>;
_mongoOptions: Object;
constructor(mongoDatabaseURI = defaults.DefaultMongoURI) { constructor(mongoDatabaseURI = defaults.DefaultMongoURI, mongoOptions = {}) {
super(); super();
this._databaseURI = mongoDatabaseURI; this._databaseURI = mongoDatabaseURI;
const defaultMongoOptions = { useNewUrlParser: true };
this._mongoOptions = Object.assign(defaultMongoOptions, mongoOptions);
} }
_connect() { _connect() {
if (!this._connectionPromise) { if (!this._connectionPromise) {
this._connectionPromise = MongoClient.connect(this._databaseURI).then( this._connectionPromise = MongoClient.connect(
client => client.db(client.s.options.dbName) this._databaseURI,
); this._mongoOptions
).then(client => client.db(client.s.options.dbName));
} }
return this._connectionPromise; return this._connectionPromise;
} }

View File

@@ -2,6 +2,7 @@
GridStoreAdapter GridStoreAdapter
Stores files in Mongo using GridStore Stores files in Mongo using GridStore
Requires the database adapter to be based on mongoclient Requires the database adapter to be based on mongoclient
(GridStore is deprecated, Please use GridFSBucket instead)
@flow weak @flow weak
*/ */
@@ -14,17 +15,22 @@ import defaults from '../../defaults';
export class GridStoreAdapter extends FilesAdapter { export class GridStoreAdapter extends FilesAdapter {
_databaseURI: string; _databaseURI: string;
_connectionPromise: Promise<Db>; _connectionPromise: Promise<Db>;
_mongoOptions: Object;
constructor(mongoDatabaseURI = defaults.DefaultMongoURI) { constructor(mongoDatabaseURI = defaults.DefaultMongoURI, mongoOptions = {}) {
super(); super();
this._databaseURI = mongoDatabaseURI; this._databaseURI = mongoDatabaseURI;
const defaultMongoOptions = { useNewUrlParser: true };
this._mongoOptions = Object.assign(defaultMongoOptions, mongoOptions);
} }
_connect() { _connect() {
if (!this._connectionPromise) { if (!this._connectionPromise) {
this._connectionPromise = MongoClient.connect(this._databaseURI).then( this._connectionPromise = MongoClient.connect(
client => client.db(client.s.options.dbName) this._databaseURI,
); this._mongoOptions
).then(client => client.db(client.s.options.dbName));
} }
return this._connectionPromise; return this._connectionPromise;
} }