I've tried in so many ways to fill an array of objects but I can't find a solution, the arrays know that by default they're always empty, but I can't find a way to populate this complex array
const mongoose = require('mongoose');
// Fasi
const DateSchema = { type: Date, default: new Date(false) };
const NumberSchema = { type: Number, default: 1 };
const StringSchema = { type: String, default: '' };
const CustomSchema = {
tempoaSchedaInOre: DateSchema,
tempoTotaleInOre: DateSchema,
tempoTotaleInMinuti: NumberSchema,
};
// End Fasi
const preventiviSchema = mongoose.Schema({
data: {
type: Date,
default: Date.now,
},
fase: {
type: [
{
controlloMaterialeSmd: CustomSchema,
equipaggiamentoSerig: CustomSchema,
equipaggiamentoPeP: CustomSchema,
},
],
},
});
mongoose.model('preventivi', preventiviSchema);
and generate this:
{
"data": {
"$date": "2020-12-24T11:02:45.322Z"
},
"fase": [],
"__v": 0
}
My intent is to generate an array with all the elements directly in the Schema,
Thanks to all