通过create-react-app访问mongodb地图集时出错

时间:2020-01-12 21:55:50

标签: node.js reactjs mongodb create-react-app mongodb-atlas

我正在使用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列入白名单。

1 个答案:

答案 0 :(得分:0)

我越关注这个问题,似乎前端和后端之间的区别就很大了。我遇到了bigquery的类似问题。由于不想创建后端,因此创建了一个google cloud function作为后端并使用了fetch。这也适用于bigquery