最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

通过邮递员将json解析为猫鼬模式,但其格式无效

IT培训 admin 14浏览 0评论

通过邮递员将json解析为猫鼬模式,但其格式无效

const Item = mongoose.model('Item',new mongoose.Schema({
    title:{
        type:String,
        trim:true,
        required:true,
        minlength:1,
        maxlength:55

    },
    authorsIds:{
        type:[
            new mongoose.Schema({
            name:{
                type:String,
                required:true,
                minlength:3,
                maxlength:55
            }
        })]
    }

我正在尝试通过邮递员将值分配给authorsIds"authorsIds":[{"name":"omer"} , {"name":"ali"}],但不接受正确的方法plz helpout

回答如下:

您应该保留两个不同的模式,其中项目模式应参考作者的引用。

通过邮递员将json解析为猫鼬模式,但其格式无效

const Item = mongoose.model('Item',new mongoose.Schema({
    title:{
        type:String,
        trim:true,
        required:true,
        minlength:1,
        maxlength:55

    },
    authorsIds:{
        type:[
            new mongoose.Schema({
            name:{
                type:String,
                required:true,
                minlength:3,
                maxlength:55
            }
        })]
    }

我正在尝试通过邮递员将值分配给authorsIds"authorsIds":[{"name":"omer"} , {"name":"ali"}],但不接受正确的方法plz helpout

回答如下:

您应该保留两个不同的模式,其中项目模式应参考作者的引用。

发布评论

评论列表 (0)

  1. 暂无评论