I have a collection to like below. I want to design a schema in mongoose...
{
"_id" : ObjectId("51da6e03e6d8e40aa4c72c28"),
"series" : [{
"type" : "pie",
"name" : "Browser share",
"data" : [["Firefox", 45.0], ["IE", 26.8], ["Safari", 8.5], ["Opera", 6.2], ["Others", 0.7]]
}]
}
My mongoose code is :
_id: false,
series: [{
type:String,
name: String,
data:[]
}]
But I am not getting that data using this schema. I am getting a blank array but I want the same data that is in that collection. Please suggest some schema structure and how I can fetch the same data using node.
this is the way i m fetching data, But i am not able to get the data: query.fetchAll(schData.schTempPI, null, function (err, result) {
console.log(result.series);
var data = chartModel.data;
for (i = 0; i < result[0].series.length; i++) {
data.series.push(result[0].series[i])
console.log(data);
}
I think to accomplish what you mean to, your schema should actually be:
var schema = new Schema({
_id: false,
series: {
type: String,
name: String,
data: [
[String, Number]
]
}
});
Or something similar. This is untested, but based on the docs I believe this is something more like what you should be going for... You could also look into SubDocuments.