【发布时间】:2019-08-24 02:26:02
【问题描述】:
我编写了一些脚本,以便使用 NodeJS 和 MongoDB 创建服务器和数据库。
我已经使用 localhost 尝试了代码,一切正常。
我在 Atlas MongoDB 创建了一个帐户,以便在在线数据库上测试应用程序。
我更改了我的 js 中的 url,因为它只在连接字符串时由 Atlas 提供:
const url = "mongodb+srv://XXX:<XXX>@XXX-uyrjt.mongodb.net/test?retryWrites=true&w=majority";
MongoClient.connect(url,{useNewUrlParser: true}, function(err,client) {
if(err)
console.log('unable to connect to mongodb server.error',err);
else{...
}
但是我得到以下错误:
【问题讨论】:
-
您确定您提供了正确的用户名并通过了吗?
标签: node.js mongodb mongodb-atlas