@klapeks/micro-db-utils 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -43,7 +43,7 @@ export declare class MongoDBConnection {
43
43
  readonly set: (model: T, value: number) => Promise<any>;
44
44
  };
45
45
  static getOptions(): MongoDBConnectOptions;
46
- static init(databaseName: string): Promise<void>;
46
+ static init(databaseName: string, replicaSet?: string): Promise<void>;
47
47
  }
48
48
  export declare const MongoGeoPoint: MongooseSchema<Point, import("mongoose").Model<Point, any, any, any, import("mongoose").Document<unknown, any, Point, any> & Point & {
49
49
  _id: import("mongoose").Types.ObjectId;
@@ -139,7 +139,7 @@ var MongoDBConnection = /** @class */ (function () {
139
139
  database: ""
140
140
  };
141
141
  };
142
- MongoDBConnection.init = function (databaseName) {
142
+ MongoDBConnection.init = function (databaseName, replicaSet) {
143
143
  return __awaiter(this, void 0, void 0, function () {
144
144
  var _a, host, port, password, username, mongoURI;
145
145
  return __generator(this, function (_b) {
@@ -147,8 +147,12 @@ var MongoDBConnection = /** @class */ (function () {
147
147
  case 0:
148
148
  if (_databaseName)
149
149
  return [2 /*return*/];
150
+ if (!replicaSet && process.env.MONGO_DATABASE_REPLICA_SET) {
151
+ replicaSet = process.env.MONGO_DATABASE_REPLICA_SET;
152
+ }
150
153
  _a = this.getOptions(), host = _a.host, port = _a.port, password = _a.password, username = _a.username;
151
- mongoURI = 'mongodb://' + host + ':' + port + '/' + databaseName;
154
+ mongoURI = 'mongodb://' + host + ':' + port + '/' + databaseName
155
+ + (replicaSet ? '?replicaSet=' + replicaSet : undefined);
152
156
  // logger.log(mongoURI);
153
157
  if (!mongooseModule)
154
158
  throw new Error("No mongoose module");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@klapeks/micro-db-utils",
3
3
  "description": "klapeks utils for db and other storages",
4
- "version": "0.0.6",
4
+ "version": "0.0.7",
5
5
  "type": "commonjs",
6
6
  "author": "Klapeks",
7
7
  "license": "ISC",