【发布时间】:2020-08-25 20:52:33
【问题描述】:
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"}] ,
但它不被接受请以正确的方式帮助
【问题讨论】:
-
请显示不起作用的代码。您正在更新 mongodb 文档吗?你在创造它吗?此外,您的
authorsIds在它有一个数组之前有一个类型键.. -
iauthorsIds:{ type:[ new mongoose.Schema({ name:{ type:String, required:true, minlength:3, maxlength:55 } })]
-
我只是通过邮递员创建 authorsIds 但它不起作用.. 我不知道如何为 authorsIds 赋值
-
可以通过邮递员成功插入
item,但是item不包含authorsIds对吧?或者如果你有authorsIds字段,你根本不能插入? -
item 包含 authorsIds 子文档...并且未插入 authorsIds 字段中的名称值,这就是问题
标签: node.js mongodb express mongoose postman