Skip to content

Commit

Permalink
feat: add MONGODB_OPTIONS to .env
Browse files Browse the repository at this point in the history
- User can add desired options to connection URL by themselves
- Also update README
  • Loading branch information
Chinlinlee committed May 5, 2023
1 parent 61a1904 commit bbfdd11
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ MONGODB_PORTS=[27017]
MONGODB_USER="root"
MONGODB_PASSWORD="root"
MONGODB_AUTH_SOURCE="admin"
MONGODB_OPTIONS=""
MONGODB_IS_SHARDING_MODE=false

# Server
Expand Down
1 change: 1 addition & 0 deletions config-class.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class MongoDbConfig {
this.user = env.get("MONGODB_USER").default("").asString();
this.password = env.get("MONGODB_PASSWORD").default("").asString();
this.authSource = env.get("MONGODB_AUTH_SOURCE").default("admin").asString();
this.urlOptions = env.get("MONGODB_OPTIONS").default("").asString();
this.isShardingMode = env.get("MONGODB_IS_SHARDING_MODE").default("false").asBool();
}
}
Expand Down
8 changes: 7 additions & 1 deletion models/mongodb/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const {
user,
password,
authSource,
isShardingMode
isShardingMode,
urlOptions
} = raccoonConfig.mongoDbConfig;
module.exports = exports = function () {

Expand All @@ -27,6 +28,11 @@ module.exports = exports = function () {
}
});
databaseUrl += `/${dbName}`;

if (urlOptions) {
databaseUrl += `?${urlOptions}`;
}

console.log(databaseUrl);
/**@type {mongoose.ConnectOptions} */
let connectionOptions = {};
Expand Down

0 comments on commit bbfdd11

Please sign in to comment.