File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ services:
1414 image : mongo:8.0
1515 command :
1616 - " --auth"
17- - " --bind_ip=127.0.0.1,::1 "
17+ - " --bind_ip_all "
1818 - " --setParameter=enableLocalhostAuthBypass=false"
1919 restart : always
2020 container_name : telegram_rp_bot_mongo
@@ -28,6 +28,7 @@ services:
2828 APP_PASS : ${APP_PASS}
2929 volumes :
3030 - mongo_data:/data/db
31+ - ./init/01-init-app-user.js:/docker-entrypoint-initdb.d/01-init-app-user.js:ro
3132 networks :
3233 - internal
3334
Original file line number Diff line number Diff line change 1+ const APP_DB = _getenv ( "APP_DB" ) || "botdb" ;
2+ const APP_USER = _getenv ( "APP_USER" ) || "botuser" ;
3+ const APP_PASS = _getenv ( "APP_PASS" ) || "change_me" ;
4+
5+ const dbh = db . getSiblingDB ( APP_DB ) ;
6+ const existing = dbh . getUser ( APP_USER ) ;
7+
8+ if ( ! existing ) {
9+ dbh . createUser ( {
10+ user : APP_USER ,
11+ pwd : APP_PASS ,
12+ roles : [ { role : "readWrite" , db : APP_DB } ]
13+ } ) ;
14+ } else {
15+ // Optional: rotate password automatically if APP_PASS changes
16+ // dbh.updateUser(APP_USER, { pwd: APP_PASS });
17+ }
You can’t perform that action at this time.
0 commit comments