I have sub document as in metrics. But I don\'t think I am saving correctly, because each document doesn\'t have metrics data correctly..instead it shows metrics: [ \'[object Ob
When including a field named type
in a sub-doc of a Mongoose schema, you need to define its type using an object or it looks to Mongoose like you're declaring the type of the parent field.
So change your schema to:
var CpuSchema = new Schema({
timeStamp : { type : Date, index: true },
avaiable : Boolean,
status : String,
metrics : [ { duration : String,
data : Number,
type : {type: String},
unit : String
} ,
{ duration : String,
data : Number,
type : {type: String},
unit : String
},
{ duration : String,
data : Number,
type : {type: String},
unit : String
}
]
});