'mongoose model how to save attribute as array of json

So i have this mongoose model

const sceSchema= new mongoose.Schema({
    Id:String,
    date:String,
    data :Array,  
});

I want the data object to be saved as an array of json and im passing that array to a .create function in my api like this (i'm using fs.readdirsync to iterate over a folder and fs.readfilesync to get the data of each json element in that folder)

   addall:function(req,res){
        
        const files=fs.readdirSync(pathjson);
        let i=0
        for (let file of files)
        {
            if (file.indexOf(".json", file.length - 5) !== -1)
            {
                i++
                console.log(file.data);
                let content=fs.readFileSync(path.join(pathjson,file))
                scemodel.create({
                    Id:i,
                    data:fs.readFileSync(path.join(pathjson,file)),
                
                },function(err,scenario){
                    if(err){
                        res.json({message:'error'+err,status:500,data:null})
                    }
                    else {
                        res.json({message:'inserted data', status:200,data:scenario})
                    }
                  
                })
         
            }
        }
        
    }

I tried using String type in my model but i got an offset error out of range when i tested the api



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source