简体   繁体   English

MongoServerError:不允许用户在 [genius-car.service] 上执行操作 [find]

[英]MongoServerError: user is not allowed to do action [find] on [genius-car.service]

I was trying to learn MongoDB CRUD operations along with node express js我试图学习 MongoDB CRUD 操作以及 node express js

when i try to go 'http://localhost:5000/service' its throwing the following error:当我尝试 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...

Code: `代码:`

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);`

If you get the error " user is not allowed to do action [insert]. In your mongoDb account, navigate to Database Access then click on the edit button for the user trying to access, navigate to special privileges and click on "Add special Previledge" select the role option and change the role to "readWriteAnyDatabase"如果您收到错误“用户不允许执行操作 [插入]。在您的 mongoDb 帐户中,导航到数据库访问,然后单击尝试访问的用户的编辑按钮,导航到特殊权限并单击“添加特殊权限" select 角色选项并将角色更改为 "readWriteAnyDatabase"

Follow the steps to fix this problem:请按照以下步骤解决此问题:

  1. Sign-In your MongoDB Atlas account登录您的 MongoDB Atlas 帐户
  2. Clicked on Database Access > Database Users > EDIT actions for certain user > Specific Privileges > Add Specific Privilege > readWriteAnyDatabase (Select Role) > Update User单击数据库访问>数据库用户>编辑特定用户的操作>特定权限>添加特定权限> readWriteAnyDatabase (选择角色)>更新用户

After following these steps, you will need to run your server again and reload the 'http://localhost:5000/service' page.完成这些步骤后,您将需要再次运行服务器重新加载“http://localhost:5000/service”页面。 If you follow all the steps correctly, then it will works.如果您正确遵循所有步骤,那么它将起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM