Skip to content

Commit

Permalink
fix: mog not connecting in the constructor (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
fdebijl committed Jan 17, 2022
1 parent 7df46fb commit 73c7d57
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/domain/type/MogOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { DbOptions, MongoClientOptions } from 'mongodb';

export type MogOptions = {
url: string;
/** Name of the DB to use */
db: string;
/** Name of the connecting application, shown in the MongoDB logs and profiler */
appName?: string;
/** Default collection that is used for all operations. If not set, a collection must be passed with every operation */
defaultCollection?: string;
Expand Down
8 changes: 5 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { MongoClient, Db, Filter, Document, WithId, InsertManyResult, InsertOneR
import { Clog, LOGLEVEL } from '@fdebijl/clog';
import fs from 'fs';

import { Attachment, InsertOptions, MogOptions, OperationOptions, GetOptions, Operation, UpdateOptions, ListOptions } from './domain';
import { CountOptions } from './domain/type/CountOptions';
import { Attachment, InsertOptions, MogOptions, OperationOptions, GetOptions, Operation, UpdateOptions, ListOptions, CountOptions } from './domain';

const mogVersion = JSON.parse(fs.readFileSync('package.json', 'utf-8')).version as string;

Expand All @@ -28,7 +27,10 @@ export class Mog {
});

try {
this.db = this.client.db(options.db, options.dbOptions);
this.db = this.client.db();
this.client.connect().then(() => {
this.db = this.client.db(options.db, options.dbOptions);
});
} catch (error) {
throw error;
}
Expand Down

0 comments on commit 73c7d57

Please sign in to comment.