Wie speichern, JSON array in mongodb collection
Ich versuche zu retten, das folgende array in mein Dokument in mongodb
{"Category_Id":"54c9c206e1f512456ada778b","Sub_category_Id":"54c9c24ee1f512456ada778d",
"features":[{"specification_field_type":"textbox","specification_name":"color","_id":"551e5f2e3bbe4691142bdeba","__v":0,"$$hashKey":"object:95"},
{"specification_field_type":"textbox","specification_name":"Call Features","_id":"551e616d3bbe4691142bdebf","__v":0,"$$hashKey":"object:97"}]}
Hier ist mein node.js code zum speichern der post-Werte in mongodb
var Category_Id = req.body.Category_Id;
var Sub_category_Id = req.body.Sub_category_Id;
var features = req.body.features;
var property =new db.properties();
property.Category_Id = Category_Id;
property.Sub_category_Id = Sub_category_Id;
property.features = features;
property.save(function (err){
var message = JSON.parse('{"status":"success","message":"Features added"}');
return res.send(200, message);
}
Wenn die Abfrage ausgeführt wird, die Funktionen Informationen gespeichert ist, auf diese Weise
Collection-schema ist
var properties = new Schema({
Category_Id : { type: String},
Sub_category_Id : { type: String},
features : { type: String}
});
Kann mir jemand helfen dieses Problem zu beheben. Danke.
Du musst angemeldet sein, um einen Kommentar abzugeben.
Es scheint, Sie erklärt
features
einen String in Ihre schema anstelle eines Arrays von Filialdokumenten. Mungo ist daher Gießen Sie das array vonreq.body
einen string, bevor es gespeichert wird. Die folgenden änderungen an Ihrem schema sollte Euch auf die richtige Spur: