我有一個應用程序,我懷疑與數據庫的權限有關的多個問題。如何在OpenShift Online 3 Dev Preview中通過shell與MongoDB交互?
然而,我無法完成諸如show dbs
之類的基本命令,以便進一步排查問題並「查看」我正在處理的內容。我已經堅持了兩天,這真的很令人沮喪。
我無論是從網上控制檯和本地終端想這一點,既沒有在登錄用戶提供的憑據:
在線控制檯
Console
>MongoDB Service
>Deployment
>Pod
>mongodb-1-vs19d
>Terminal
:
sh-4.2$ mongo
MongoDB shell version: 2.6.9
connecting to: test
> show dbs
2016-07-13T04:33:10.809-0400 listDatabases failed:{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { listDatabases:
1.0 }",
"code" : 13
} at src/mongo/shell/mongo.js:47
本地終端
[email protected]:~$ oc rsh mongodb-1-vs19d
sh-4.2$ mongo
MongoDB shell version: 2.6.9
connecting to: test
> show dbs
2016-07-13T04:35:06.449-0400 listDatabases failed:{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
"code" : 13
} at src/mongo/shell/mongo.js:47
本地終端使用用戶憑據
[email protected]:~$ oc rsh mongodb-1-vs19d
sh-4.2$ mongo -u $MONGODB_USER -p $MONGODB_PASSWORD $MONGODB_DATABASE
MongoDB shell version: 2.6.9
connecting to: users
> show dbs
2016-07-13T04:51:39.127-0400 listDatabases failed:{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
"code" : 13
} at src/mongo/shell/mongo.js:47
故障排除envars
是正確的:
[email protected]:~$ oc env pods mongodb-1-vs19d --list
# pods mongodb-1-vs19d, container mongodb
MONGODB_USER=admin
MONGODB_PASSWORD=secret
MONGODB_DATABASE=users
MONGODB_ADMIN_PASSWORD=very-secret
的數據庫是從本地終端創建了:
oc new-app mongodb-persistent -p MONGODB_USER=admin,MONGODB_PASSWORD=secret,MONGODB_ADMIN_PASSWORD=very-secret
按照官方的文檔:
https://docs.openshift.com/online/getting_started/beyond_the_basics.html#btb-provisioning-a-database
使用您提供的登錄聲明允許我從本地終端和'show dbs'登錄,這非常棒。關於爲什麼'$ MONGODB_USER'被命名爲'admin' - 文檔說這樣設置數據庫:'$ oc new-app mongodb-persistent -p MONGODB_USER = admin,MONGODB_PASSWORD = secret,MONGODB_ADMIN_PASSWORD = super-secret' 。請參閱:https://docs.openshift.com/online/getting_started/beyond_the_basics.html#btb-provisioning-a-database我很感謝有關應該採取哪些措施的任何說明。此外,應用程序使用什麼用戶名和密碼登錄?管理員還是? – user1063287