angularjs - Angular is not sending objects in objects -


i'm sending json angular.js node.js/express.js service:

{   "name": "myguitar",   "type": "electric",   "userid": "123",   "likes": 0,   "dislike": 0,   "guitarparts": { "body": {   "material": "/content/img/hout.jpg",   "_id": "5566d6af274e63cf4f790858",   "color": "#921d1d" }, "head": {  }, "neck": {   "material": "/content/img/hout.jpg",   "_id": "556d9beed90b983527c684be",   "color": "#46921d" }, "frets": {  }, "pickup": {  }, "bridge": {  }, "buttons": {  } 

} }

the guitarparts not saved in mongodb database. mongoose inserts following:

mongoose: guitars.insert({ name: 'myguitar', type: 'electric', userid: '123', likes: 0, _id: objectid("557023af9b321b541d4d416e"), guitarparts: [], __v: 0})

this mongoose model:

   guitarpart = new schema({      id: { type: string, required: true },      color: { type: string, required: true },      material: { type: string, required: true },      x: { type: number, required: false },      y: { type: number, required: false },      width: { type: number, required: false },      height: { type: number, required: false},   });    guitarparts = new schema({       body: [guitarpart],       neck: [guitarpart],       head: [guitarpart],       bridge: [guitarpart],       frets: [guitarpart],       pickup: [guitarpart],       buttons: [guitarpart]   });    guitar = new schema({       name: { type: string, required: true, unique: false },       type: { type: string, required: true },       userid: { type: string },       likes: { type: number },       dislikes: { type: number },       guitarparts: [guitarparts],       kidsguitar: { type: boolean },       lefthanded: { type: boolean },       assemblykit: { type: boolean }   },   {        collection: 'guitars'    });   

i don't know what's going wrong. ideas?

according mongoose documentation of subdocuments says: sub-documents docs schemas of own elements of parents document array

and in schema provided: guitarparts not array, object , guitarpart not array object too. that's why not saving.

so correct way model schema be:

var guitardefinition = {   _id: {type: string, required: true},   color: {type: string, required: true},   material: {type: string, required: true},   x: number,   y: number,   width: number,   heigth: number };  var guitarschema = schema({   name: { type: string, required: true, unique: false },     type: { type: string, required: true },     userid: string,     likes: number,     dislikes: number ,     kidsguitar: boolean,     lefthanded: boolean ,     assemblykit: boolean,    guitarparts: {     body: guitardefinition,       neck: guitardefinition,       head: guitardefinition,       bridge: guitardefinition,       frets: guitardefinition,       pickup: guitardefinition,       buttons: guitardefinition    } }); 

actually have run in computer , saving can see complete code here: https://gist.github.com/wilsonbalderrama/f10c38f9fb510865edc2


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -