【问题标题】:Errors on accessing mongodb atlas through create-react-app通过 create-react-app 访问 mongodb atlas 的错误
【发布时间】: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


【解决方案1】:

我对此进行的研究越多,似乎前端和后端之间的区别就很重要。我遇到了bigquery 的类似问题。由于我不想做后端,所以我创建了一个google cloud function 作为后端并使用了fetch。这也适用于bigquery

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-14
    • 1970-01-01
    • 1970-01-01
    • 2018-11-05
    • 2019-01-22
    • 2017-02-18
    • 2021-04-24
    相关资源
    最近更新 更多