我正在尝试学习mongodb CRUD操作和node express js。
当我尝试去‘http://localhost:5000/service’它抛出以下错误:
D:Projects_WebDevBackEndserver-genius-car-servicenode_modulesmongodblibcmapconnection.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_WebDevBackEndserver-genius-car-servicenode_modulesmongodblibcmapconnection.js:207:30)
at MessageStream.<anonymous> (D:Projects_WebDevBackEndserver-genius-car-servicenode_modulesmongodblibcmapconnection.js:60:60)
at MessageStream.emit (node:events:527:28)
at processIncomingData (D:Projects_WebDevBackEndserver-genius-car-servicenode_modulesmongodblibcmapmessage_stream.js:132:20)
at MessageStream._write (D:Projects_WebDevBackEndserver-genius-car-servicenode_modulesmongodblibcmapmessage_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);`
1条答案
按热度按时间yh2wf1be1#
如果您收到错误消息“用户不允许执行操作[INSERT]。在您的MongoDB帐户中,导航到数据库访问,然后单击尝试访问的用户的编辑按钮,导航到特殊权限并单击”添加特殊权限“,选择角色选项并将角色更改为”ReadWriteAnyDatabase“