【发布时间】:2022-02-11 20:27:35
【问题描述】:
我正在尝试发送一个发布请求来为用户创建一个新任务,每个任务的猫鼬模式是:
let todoSchema = new AppSchema ({
userId: String,
title: String,
completed: Boolean
}, {versionKey: false})
当我发送请求时,任务是在没有用户 ID 的情况下创建的。 这是请求:
add = () => {
const task = {
userId: this.props.id,
title: this.state.title,
completed: false,
}
if(task.title) {
axiosUtils.create('http://localhost:8000/todos/', task)
alert('task created!')
}
}
*task.userId的typeof是string,是具体用户toString()的mongoDB_id
【问题讨论】:
-
调用时是否定义了“this.props.id”?
-
是的,当我使用 console.log(task.userId) 运行该函数时,它会显示 id
标签: reactjs mongodb mongoose axios mongoose-schema