使用mongodb時,出現“not master and slaveok=false”錯誤,原因是secondary不允許讀寫。
因為系統中mongodb做了主備,主備切換了,也可能導致這個問題。
把命令mongo --username=root --password=123456 --host=192.168.0.100 admin中的ip換成主ip后查詢正常。
問題說明:
首先這是正常的,因為SECONDARY是不允許讀寫的, 在寫多讀少的應用中,使用Replica Sets來實現讀寫分離。通過在連接時指定或者在主庫指定slaveOk,由Secondary來分擔讀的壓力,Primary只承擔寫操作。
對于replica set 中的secondary 節點默認是不可讀的,

在主庫上設置 slaveok=ok

總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對腳本之家的支持。如果你想了解更多相關內容請查看下面相關鏈接
您可能感興趣的文章:- 解決啟動MongoDB錯誤:error while loading shared libraries: libstdc++.so.6:cannot open shared object file:
- 關于Mongodb參數說明與常見錯誤處理的總結
- Mongodb常見錯誤與解決方法小結(Mongodb中經常出現的錯誤)
- MongoDB錯誤32-bit servers don''t have journaling enabled by default解決方法
- 解決mongodb在ubuntu下啟動失敗,提示couldn‘t remove fs lock errno:9 Bad file descriptor的錯誤
- mongodb錯誤tcmalloc: large alloc out of memory, printing stack and exiting解決辦法
- 修復 Mac brew 安裝 mongodb 報 Error: No available formula with the name ‘mongodb’ 問題詳解