[英]Am getting this error. MongoServerError: user is not allowed to do action [remove] on [shoeDatabase.users]
[英]MongoServerError: user is not allowed to do action [find] on [genius-car.service]
我試圖學習 MongoDB CRUD 操作以及 node express js
當我嘗試 go 'http://localhost:5000/service' 它拋出以下錯誤:
D:\Projects_WebDev\BackEnd\server-genius-car-service\node_modules\mongodb\lib\cmap\connection.js:207
callback(new error_1.MongoServerError(document));
^
MongoServerError: user is not allowed to do action [find] on [genius-car.service]
at Connection.onMessage (D:\Projects_WebDev\BackEnd\server-genius-car-service\node_modules\mongodb\lib\cmap\connection.js:207:30)
at MessageStream.<anonymous> (D:\Projects_WebDev\BackEnd\server-genius-car-service\node_modules\mongodb\lib\cmap\connection.js:60:60)
at MessageStream.emit (node:events:527:28)
at processIncomingData (D:\Projects_WebDev\BackEnd\server-genius-car-service\node_modules\mongodb\lib\cmap\message_stream.js:132:20)
at MessageStream._write (D:\Projects_WebDev\BackEnd\server-genius-car-service\node_modules\mongodb\lib\cmap\message_stream.js:33:9)
at writeOrBuffer (node:internal/streams/writable:389:12)
at _write (node:internal/streams/writable:330:10)
at MessageStream.Writable.write (node:internal/streams/writable:334:10)
at TLSSocket.ondata (node:internal/streams/readable:754:22)
at TLSSocket.emit (node:events:527:28) {
ok: 0,
code: 8000,
codeName: 'AtlasError',
[Symbol(errorLabels)]: Set(0) {}
}
[nodemon] app crashed - waiting for file changes before starting...
代碼:`
async function run() {
try {
await client.connect();
const serviceCollection = client.db('genius-car').collection('service');
app.get('/service', async (req, res) => {
const query = {};
const cursor = serviceCollection.find(query);
const services = await cursor.toArray();
res.send(services)
});
} finally {
//
}
}
run().catch(console.dir);`
如果您收到錯誤“用戶不允許執行操作 [插入]。在您的 mongoDb 帳戶中,導航到數據庫訪問,然后單擊嘗試訪問的用戶的編輯按鈕,導航到特殊權限並單擊“添加特殊權限" select 角色選項並將角色更改為 "readWriteAnyDatabase"
請按照以下步驟解決此問題:
完成這些步驟后,您將需要再次運行服務器並重新加載“http://localhost:5000/service”頁面。 如果您正確遵循所有步驟,那么它將起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.