this is my mongoose schema
which includes nested arrays and objects.
classes:[{
LP:[
{
one:[
{
division:String,
strength:String
}
]
}
]
}]
});
and this is how i insert values,
var SchoolDetails=new school_details({
classes:[
{
LP:[
{
ONE:[
{
division: "A",
stregth: "20"
},
{
division: "A",
stregth: "20"
},
{
division: "A",
stregth: "20"
},
{
division: "A",
stregth: "20"
}
]
},
{
TWO:[
{
division: "A",
stregth: "20"
},
{
division: "A",
stregth: "20"
},
{
division: "A",
stregth: "20"
},
{
division: "A",
stregth: "20"
}
]
}
],
UP:[
{
ONE:[
{
division: "A",
stregth: "20"
},
{
division: "A",
stregth: "20"
},
{
division: "A",
stregth: "20"
},
{
division: "A",
stregth: "20"
}
]
},
{
TWO:[
{
division: "A",
stregth: "20"
},
{
division: "A",
stregth: "20"
},
{
division: "A",
stregth: "20"
},
{
division: "A",
stregth: "20"
}
]
}
]
}
]
});
SchoolDetails.save(function (err,data) {
if(err){
console.log(err);
}
console.log("School Details ;"+data);
});
but the document get saved like this,
{
"_id" : ObjectId("5a06ddb228603b2888d3076e"),
"classes" : [
{
"_id" : ObjectId("5a06ddb228603b2888d3076f"),
"LP" : [
{
"_id" : ObjectId("5a06ddb228603b2888d30771"),
"one" : [ ]
},
{
"_id" : ObjectId("5a06ddb228603b2888d30770"),
"one" : [ ]
}
]
}
],
"__v" : 0
}
The document is not saving all the values. only one value in array is getting saved. why? is my schema is wrong? or the way i inserting values is wrong ? what i am doing wrong ? please help..