首頁 > 軟體

mongodb root使用者建立資料庫提示not master的解決

2023-02-20 06:01:21

mongodb root使用者建立資料庫提示not master

問題如題 

問題也比較簡單, 就是master掛了

mongodb的叢集似乎和mysql,redis的不太一樣,這個我也不太清楚

總之單機不會出現這種情況,叢集會出現

解決方法

就是將master重啟就可以了

mongodb "errmsg" : "not master and slaveOk=false"的解決

是正常的,因為SECONDARY是不允許讀寫的,如果非要解決執行 rs.slaveOk() 這句命令就可以了

[yukw@mongodb4 data]$ ./mongo -port 20000
MongoDB shell version v3.4.4
connecting to: mongodb://127.0.0.1:20000/
MongoDB server version: 3.4.4
Server has startup warnings:
2019-07-31T17:06:43.397+0800 I CONTROL  [initandlisten]
2019-07-31T17:06:43.397+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-07-31T17:06:43.398+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2019-07-31T17:06:43.398+0800 I CONTROL  [initandlisten]
2019-07-31T17:06:43.398+0800 I CONTROL  [initandlisten]
2019-07-31T17:06:43.398+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2019-07-31T17:06:43.398+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2019-07-31T17:06:43.398+0800 I CONTROL  [initandlisten]
2019-07-31T17:06:43.398+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2019-07-31T17:06:43.398+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2019-07-31T17:06:43.398+0800 I CONTROL  [initandlisten]

> show users
2019-07-31T17:07:33.469+0800 E QUERY    [thread1] Error: not master and slaveOk=false :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
DB.prototype.getUsers@src/mongo/shell/db.js:1537:1
shellHelper.show@src/mongo/shell/utils.js:752:9
shellHelper@src/mongo/shell/utils.js:659:15
@(shellhelp2):1:1
> show dbs
2019-07-31T17:07:39.126+0800 E QUERY    [thread1] Error: listDatabases failed:{
    "ok" : 0,
    "errmsg" : "not master and slaveOk=false",                    ##報錯提示
    "code" : 13435,
    "codeName" : "NotMasterNoSlaveOk"
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:62:1
shellHelper.show@src/mongo/shell/utils.js:769:19
shellHelper@src/mongo/shell/utils.js:659:15
@(shellhelp2):1:1
> rs.slaveOk();                                   ##執行命令    
> show dbs
local  0.000GB
> show users

好了,這就是解決not master and slaveOk=false的方法了

總結

以上為個人經驗,希望能給大家一個參考,也希望大家多多支援it145.com。


IT145.com E-mail:sddin#qq.com