NodeJS Postman 卡在“发送请求...”

yhxst69z  于 2023-05-22  发布在  Node.js
关注(0)|答案(1)|浏览(145)

我正在尝试创建Note.js(model)的示例“note”
通过postman raw json发送post请求

{
    "user": "645xxxxxxxxxxxxxxxxxxx88d",
    "title": "title",
    "text": "description"
}

它被卡在行:Notes控制器中的const note = await Note.create({ user })
在这一行之后有一个if(note)返回响应,但它似乎没有到达那里。
我认为代码是好的,因为我一直在遵循教程。我在server.js文件中确实有app.use(express.json());console.log(Note.create(noteObject))输出Promise { <pending> }
更新:
所以很明显,注解掉这个Node.js文件中的注解代码可以让它运行得很好。但我不应该这样做。出了什么问题怎么解决

const mongoose = require('mongoose')
const AutoIncrement = require('mongoose-sequence')(mongoose)

const noteSchema = new mongoose.Schema(
    {
        user: {
            type: mongoose.Schema.Types.ObjectId,
            required: true,
            ref: 'User'
        },
        title: {
            type: String,
            required: true
        },
        text: {
            type: String,
            required: true
        },
        completed: {
            type: Boolean,
            default: false
        }
    },
    {
       timestamps: true
    }
)

//noteSchema.plugin(AutoIncrement, {
//    inc_field: 'ticket',
//    id: 'ticketNums',
//    start_seq: 500
//})

module.exports = mongoose.model('Note', noteSchema)

控制器文件使用'express-async-handler',mongoErrLog.log和errLog.log文件没有更新,但reqLog.log文件记录以下条目:
POST /notes undefined

gtlvzcf8

gtlvzcf81#

看起来像mongoose-sequence和最新mongoose版本之间的已知问题:https://github.com/ramiel/mongoose-sequence/issues/133
您可以将mongoose版本降级到兼容版本,例如。npm i mongoose@6.5.0

相关问题