是否有人知道如何修复此错误(TypeError:无法分配给对象';#<;QueryCursor&>';的只读属性';map';) [英] Does anyone know nay fix for this error (TypeError: Cannot assign to read only property 'map' of object '#<QueryCursor>')
本文介绍了是否有人知道如何修复此错误(TypeError:无法分配给对象';#<;QueryCursor&>';的只读属性';map';)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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);
}
};
错误发生在const res = await fetch("/api/sendChoice" ,{
error - TypeError: Cannot assign to read only property 'map' of object '#<QueryCursor>'
在Inspect元素中,错误为
this
我找不到与解决此问题相关的任何内容,我甚至不明白尝试自己解决此问题是什么意思。
来自我的项目的其他一些相关代码 接口/sendChoiceimport { getSession } from "next-auth/client";
import dbConnect from "../../helpers/dbConnect";
import Choice from "../../models/Choice";
export default async function sendChoice(req, res) {
try {
const session = await getSession({ req });
await dbConnect();
if (!session) {
res.status(401).send("You are not signed in");
return;
}
if (req.method === "POST") {
console.log(req.body);
const { choiceSeq, checkSubmit } = req.body;
console.log(choiceSeq, checkSubmit);
const userId = session.user.id;
const nameP = session.user.name;
const choice = new Choice({
user: userId,
name: nameP,
choiceSeq,
checkSubmit,
});
await choice.save();
res.status(200).send("Choice saved");
} else {
res.status(400).send("Bad request");
}
}
catch (error) {
console.log(error);
}
}
MongoDB架构
import mongoose, { Schema } from 'mongoose';
const ChoiceSchema = new Schema({
user: {
type: Schema.Types.ObjectId,
ref: 'User',
},
name: {
type: String,
},
choiceSeq: {
type: Array,
default: [],
},
checkSubmit: {
type: Boolean,
}
});
mongoose.models = {};
export default mongoose.model('Choice', ChoiceSchema);
推荐答案
17.5.0版的最新更新导致此错误。您必须将节点js重新安装到版本16.14.0 LTS。您应该始终使用LTS版本
这篇关于是否有人知道如何修复此错误(TypeError:无法分配给对象';#<;QueryCursor&>';的只读属性';map';)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文