json - Unable to access objects in req.body array from Mongoose -
orderschema
var orderschema = new schema({ orderdate : {type: date, default: date.now()}, userid : {type : number, ref:'user', default: '0'}, totalprice : {type : number, default: '0'}, totalquantity : {type : number, default: '0'}, status : {type : boolean, default: 'false'}, items : [{ _id : {type: schema.types.objectid, ref:'product'}, quantity : {type : number, default: '0'} }] })
on posting via postman , console.log(req.body) form nodejs server returns
{ totalprice : '755', totalquantity: '12', userid: '3423324242', address: 'dsadsd', items: '{'_id':'5528cfd2e70144e020cb6495', 'quantity':'1' },{'_id':'5528cfd2e70144e012ab6495','quantity':'5' },{'_id':'5528cfd2e70144e020bd6495', 'quantity':'435' },{'_id':'5528cfd2e12144e012ab6495','quantity':'3' }' }
first of i'm not able access objects in items e.g. items[0] returns '{' maybe because treating char array. second wanna create new order instance , make loop push item objects items array of orderschema. far success i've got saving data in items array send individually _id , quantity , push
order.items.push({ '_id' : req.body._id, 'quantity' : req.body.quantity })
but using above method wont able push multiple item objects array these items objects sent shopping cart. want create new order , push these items in items array
Comments
Post a Comment