我送這個JSON與Angular.js我的node.js/express.js服務:角不在對象發送對象
{
"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": {
}
}}
的guitarParts不會保存在MongoDB數據庫中。 貓鼬插入以下:
貓鼬:guitars.insert({名稱: 'MyGuitar',類型: '電動',用戶ID: '123',喜歡:0,_id:的ObjectId( 「557023af9b321b541d4d416e」),guitarParts: [],__v:0})
這是我的貓鼬模型:
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'
});
我不知道發生了什麼錯誤。有任何想法嗎?
錯字'guitarparts' - >'guitarParts'? – Pavlo
感謝您的回答。我嘗試過,但仍然無法正常工作。 – Koen