I’m getting information from a web API and I want to save the data to the database.
The problem is that when you save, only the _id is registered.
I’m saving the data like this:
const Datas = db.datas;
.
.
averages = response.data.data[0].quality[0].average.map(a => ({ status: a.status, type: a.type }))
const data = new Datas({
.
.
quality: [{
"cod": cod,
"month": month,
average: averages,
}],
.
.
.
await data.save();
I tested a console.log(means) and got the array correctly.
I declare the model this way:
var averageSchema = new mongoose.Schema({
status: String,
type: String,
});
.
.
quality: [{
average: [{averageSchema}],
}],
The end result is this:
How do I save the other array data correctly?
I appreciate if anyone can help me analyze!