我通过 Mongoose 将数据发送到 MongoDB。现在,在为其获取 API 路由期间,会抛出错误。
代码
const addChoice = async (e) => {
try {
e.preventDefault();
const res = await fetch("/api/sendChoice", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
choiceSeq: choice,
checkSubmit: true,
}),
});
console.log(res);
router.push("/home");
} catch (error) {
console.log(error);
}
};
Run Code Online (Sandbox Code Playgroud)
错误发生在const res = await fetch("/api/sendChoice" ,{
在终端服务器中出现错误
错误 - TypeError:无法分配给对象“#<QueryCursor>”的只读属性“map”
我找不到与解决此问题相关的任何内容,我什至不明白该错误意味着什么,试图自己解决它。
我的项目中的其他一些相关代码:
api/sendChoice
import { getSession } from "next-auth/client";
import dbConnect from "../../helpers/dbConnect";
import Choice from "../../models/Choice";
export default async function …Run Code Online (Sandbox Code Playgroud)