Postman卡在“Sending request...”,问题处理类型:mongoose.Schema.Types.ObjectId

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

我正在尝试创建具有模式的 Note.js(模型)实例“note”

const noteSchema = new mongoose.Schema(
{
    user: {
        type: mongoose.Schema.Types.ObjectId,
        required: true,
        ref: 'User'
    }
}

通过 postman raw json 发送一个 post 请求

{
    "user": "645xxxxxxxxxxxxxxxxxxx88d"
}

卡在了线上:

const note = await Note.create({ user }) 
在笔记控制器中

此行之后有一个 if(note) 返回响应,但它似乎没有到达那里。

我应该如何发送请求?

我认为代码很好,因为我一直在学习教程。 我在 server.js 文件中确实有

app.use(express.json());
我尝试了不同的语法,但都导致了错误,一个突出的错误是 BSONError。

node.js json mongoose postman mongoose-schema
© www.soinside.com 2019 - 2024. All rights reserved.