0

I want to pass my array of string to my schema. As you can see in auth.js image:image here I am passing my image array to my mongodb property image and i am getting array of strings successfully in image but I tried everything like $push, $each but i don't know how to pass the image array to my Mongodb schema. I hope you understand my query.

Schema.js

const mongoose=require('mongoose');

const mySchema=mongoose.Schema({
    
    image:{
        type:[String],
        required:true,
        value:[String]
    }
    
})


const MyCattle=mongoose.model('cattle_list',mySchema);

auth.js

const finaldata = new MyCattle({
        image:[image]
    })
    
    module.exports=MyCattle;

1 Answers1

0

I believe this is a duplicate of this question, but I shall share the answer here:

const mySchema = mongoose.Schema({
    image: {
        type: [{ type: String }]
    }
});

// ...
Zipper
  • 181
  • 1
  • 10
  • I tried your code but it still showing me the error i.e ( ValidationError: image.0: Cast to [string] failed for value "[{"image":["sprat (2).jpg"]}]" at path "image.0" ) – Muhammad Usman May 29 '21 at 08:22