【发布时间】:2015-06-13 08:31:28
【问题描述】:
我正在尝试将以下数组保存到 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"}]}
这是我的 node.js 代码,用于将帖子值保存在 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);
}
虽然执行了查询,但是features信息是这样保存的
集合架构是
var properties = new Schema({
Category_Id : { type: String},
Sub_category_Id : { type: String},
features : { type: String}
});
谁能帮我解决这个问题。谢谢。
【问题讨论】:
标签: json node.js mongodb mongoose bson