在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();
}
在前端有输入字段和一个按钮,当单击按钮时我会收到错误。
如果知道解决办法请告知。 预先感谢。
您需要在“mongodb.net/”后面的连接字符串中提及数据库的名称
示例:'mongodb+srv://vivek:[电子邮件受保护]/"yourDatabaseName"?retryWrites=true&w=majority&appName=Cluster0