简体   繁体   English

弃用警告后显示“不允许用户执行操作”

[英]“User is not allowed to do action” following a DeprecationWarning

While working on some new (very simple) server code, I connected and inserted MongoDB URL code in order to "deploy" it on MongoDB Atlas. 在处理一些新的(非常简单的)服务器代码时,我连接并插入了MongoDB URL代码,以便在MongoDB Atlas上“部署”它。

However, I get the following warning: 但是,我收到以下警告:

(node:3396) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. (节点:3396)DeprecationWarning:不建议使用当前的URL字符串解析器,并将在以后的版本中将其删除。 To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect. 要使用新的解析器,请将选项{useNewUrlParser:true}传递给MongoClient.connect。

This doesn't prevent my code from deploying to the server, and still allows me to send requests with a local testing tool (Postman). 这不会阻止我的代码部署到服务器,仍然允许我使用本地测试工具(邮递员)发送请求。 However, after my requests are sent, I get the following message in VS Code: 但是,发送请求后,我在VS Code中收到以下消息:

{ MongoError: user is not allowed to do action [insert] on [agenda.contacts]
    at Connection.<anonymous> (C:\Users\mymachine\agenda\node_modules\mongodb-core\lib\connection\pool.js:443:61)
    at Connection.emit (events.js:198:13)
    at processMessage (C:\Users\mymachine\agenda\node_modules\mongodb-core\lib\connection\connection.js:364:10)
    at TLSSocket.<anonymous> (C:\Users\mymachine\agenda\node_modules\mongodb-core\lib\connection\connection.js:533:15)
    at TLSSocket.emit (events.js:198:13)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at TLSSocket.Readable.push (_stream_readable.js:224:10)
    at TLSWrap.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
  ok: 0,

I suspect this is probably a version error, however this is out of my area of expertise. 我怀疑这可能是版本错误,但是这超出了我的专业知识范围。

My setup is very simple and has only the Atlas cluster connected on MongoDB website. 我的设置非常简单,并且仅在MongoDB网站上连接了Atlas集群。

MongoDB still provides all the analytics I need, so it doesn't seem to have a problem there. MongoDB仍然提供了我需要的所有分析,因此那里似乎没有问题。

I've already tried changing mongoClient.connect code from useMongoClient: true to useNewUrlParser: true , but it only changes the warning message code from (node:3396) to (node:1092) . 我已经尝试将mongoClient.connect代码从useMongoClient: true更改为useNewUrlParser: true ,但是它仅将警告消息代码从(node:3396)更改为(node:1092)

mongoose.connect(
    '*inserted mongodb url code, copied from CONNECTION STRING ONLY");
    {
        useNewUrlParser: true
    }

Since I have never used MongoDB, I believe my issue is on that software. 由于我从未使用过MongoDB,因此我认为问题出在该软件上。

I copied the CONNECTION STRING ONLY instead of FULL DRIVER EXAMPLE (both provide a code to insert into my code in VS Code. 我仅复制了“连接字符串”,而不是“完整驱动程序示例”(两者均提供了要插入到VS Code中的代码中的代码)。

As to the (node(1234)) issue solved above, it was in regards to a Warning about a newer version, as to call useNewUrlParser: true instead of useMongoClient: true . 对于上面解决的(node(1234))问题,它是关于一个较新版本的警告,称为useNewUrlParser: true而不是useMongoClient: true

As to the "MongoError", I was, instead of hardcoding my password, calling a + process.env.MONGO_ATLAS_PW + and sending my password to file ./nodemon.json . 至于“ MongoError”,我不是对密码进行硬编码,而是调用+ process.env.MONGO_ATLAS_PW +并将密码发送到文件./nodemon.json

After changing both errors, code ran smoothly. 更改了两个错误后,代码运行平稳。 I, however, will have to find a new way to send password, instead of hardcoding it. 但是,我将不得不找到一种发送密码的新方法,而不是对其进行硬编码。

Thank you all who has helped. 谢谢所有帮助的人。

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

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