【发布时间】:2020-01-12 21:55:50
【问题描述】:
我正在使用 mongodb atlas 建议的标准连接
const MongoClient = require('mongodb').MongoClient;
const uri = "mongodb+srv://<username>:<password>@cluster0-4azjv.gcp.mongodb.net/test?retryWrites=true&w=majority";
const client = new MongoClient(uri, { useNewUrlParser: true });
client.connect(err => {
const collection = client.db("test").collection("devices");
// perform actions on the collection object
client.close();
});
我收到以下错误
TypeError: Cannot read property 'replace' of undefined
at matchesParentDomain (uri_parser.js:30)
at uri_parser.js:71
我已将0.0.0.0/0 列入我的白名单。
【问题讨论】:
-
你是如何将用户名和密码传递给uri的?
-
通过这一行 "mongodb+srv://
: @cluster0-4azjv.gcp.mongodb.net/test?retryWrites=true&w=majority" -
您是否完全替换了
和 ? -
尝试输入硬编码用户名和密码
-
我已经尝试重现您的问题,但我无法成功,您有任何沙箱或 GitHub 存储库吗?
标签: node.js reactjs mongodb create-react-app mongodb-atlas