我收到此错误“不支持 URL 方案“mongodb+srv”。”

问题描述 投票:0回答:1

在react.js中,我使用post方法进行api调用,但在控制台中收到错误。

这是我的后端代码

 const editNote = async (id, title, description, tag) => {
    //api call
const host = 'mongodb+srv://vivek:[email protected]/?retryWrites=true&w=majority&appName=Cluster0'

    const response = await fetch(`${host}/api/notes/updatenote/${id}`, {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "auth-token":
          "xyz",
      },
      body: JSON.stringify({ title, description, tag }),
    });
    const json = response.json();
}

在前端有输入字段和一个按钮,当单击按钮时我会收到错误。

 Frontend

 error in the console

如果知道解决办法请告知。 预先感谢。

node.js mongodb fetch mongodb-atlas
1个回答
0
投票

您需要在“mongodb.net/”后面的连接字符串中提及数据库的名称

示例:'mongodb+srv://vivek:[电子邮件受保护]/"yourDatabaseName"?retryWrites=true&w=majority&appName=Cluster0

© www.soinside.com 2019 - 2024. All rights reserved.