将字符串数组传递给MongoDb架构
我想将字符串数组传递给架构。正如您在auth.jsimage:image中所看到的,我正在将我的图像数组传递给我的mongodb属性图像,并且我在image中成功地获得了字符串数组,但是我尝试了所有方法,比如$push,$each,但我不知道如何将图像数组传递给我的mongodb架构。我希望你能理解我的疑问 Schema.js将字符串数组传递给MongoDb架构,mongodb,express,mongoose,Mongodb,Express,Mongoose,我想将字符串数组传递给架构。正如您在auth.jsimage:image中所看到的,我正在将我的图像数组传递给我的mongodb属性图像,并且我在image中成功地获得了字符串数组,但是我尝试了所有方法,比如$push,$each,但我不知道如何将图像数组传递给我的mongodb架构。我希望你能理解我的疑问 Schema.js const mongoose=require('mongoose'); const mySchema=mongoose.Schema({ image:
const mongoose=require('mongoose');
const mySchema=mongoose.Schema({
image:{
type:[String],
required:true,
value:[String]
}
})
const MyCattle=mongoose.model('cattle_list',mySchema);
const finaldata = new MyCattle({
image:[image]
})
module.exports=MyCattle;
auth.js
const mongoose=require('mongoose');
const mySchema=mongoose.Schema({
image:{
type:[String],
required:true,
value:[String]
}
})
const MyCattle=mongoose.model('cattle_list',mySchema);
const finaldata = new MyCattle({
image:[image]
})
module.exports=MyCattle;
我相信这是一个复制品,但我将在这里分享答案:
const mySchema=mongoose.Schema({
图片:{
类型:[{type:String}]
}
});
// ...
这是否回答了您的问题?我不想存储图像。我想传递包含图像名称的字符串数组。我尝试了您的代码,但它仍然显示错误,即(ValidationError:image.0:对路径“image.0”处的值“[{”image:[“sprat(2.jpg“]}]”转换为[string]失败)