express - Adding dynamic values to MongoDB embedded collections -


i developing expressjs application. have user schema embedded collections. wondering if there techniques can use inorder post embedded collections dynamically. instance :

below have "a" embedded collection 2 values x , y. possible post values dynamically instead of having x , y if wanna post x---xn ?

var user = mongoose.schema( { _id: {type: string, required:true}, name : string, a: { x: {sensor_id: string, sname: string, time:string, value: number }, y: {sensor_id1: string, sname1: string, time1:string, value1: number } }, a1 : { x: {sensor_id2: string, sname2: string, time2:string, value2: number}, y: {sensor_id3: string, sname3: string, time3:string, value3: number } }}); 

while want post values :

var user = new user(); user.a.x.sensor_id = req.body.sensor_id; user.a.y.sname = req.body.sname; 

i wondering if there techniques can post number of values embedded collection "a"?

did tried ?

var user = mongoose.schema( {  _id: {type: string, required:true},  name : string,  a:[ {       x: {sensor_id: string, sname: string, time:string, value: number },       y: {sensor_id1: string, sname1: string, time1:string, value1: number }   }] }); 

then after..

var user = new user(); user.a = [{x:sensor_id},{y:req.body.sensor_id},{x:sensor_id2},{y:req.body.sensor_id2}]; 

Comments