Skip to content

Commit

Permalink
feat: support connect to mongodb atlas cluster (#798)
Browse files Browse the repository at this point in the history
  • Loading branch information
wibus-wee authored May 28, 2023
1 parent 6b8ee13 commit 5cfb1be
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion apps/core/src/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,19 @@ export const MONGO_DB = {
port: CONFIG.db_port || 27017,
user: CONFIG.db_user || '',
password: CONFIG.db_password || '',
isAtlas: CONFIG.db_atlas || false,
userAndPassword:
CONFIG.db_user && CONFIG.db_password
? `${CONFIG.db_user}:${CONFIG.db_password}@`
: '',
get uri() {
return `mongodb://${this.userAndPassword}${this.host}:${this.port}${
if (this.isAtlas) {
return `mongodb+srv://${this.userAndPassword}${this.host}/${this.dbName}?retryWrites=true&w=majority`;
} else {
return `mongodb://${this.userAndPassword}${this.host}:${this.port}${
CONFIG.railway ? '' : `/${this.dbName}`
}`;
}
},
};

Expand Down
1 change: 1 addition & 0 deletions shared/commander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const BasicCommer = program
.option('-P, --db_port <port>', 'port of database 数据库端口')
.option('-U, --db_user <user>', 'user of database 数据库用户名')
.option('-W, --db_password <password>', 'password of database 数据库密码')
.option('-A, --db_atlas', 'is atlas 是否是Atlas数据库')

.option('-RH, --redis_host <host>', 'host of redis redis地址')
.option('-RP, --redis_port <port>', 'port of redis redis端口')
Expand Down

0 comments on commit 5cfb1be

Please sign in to comment.