现在我的json是这样的:
{
"_id" = 53a8a41c360ce27c26c374f1;
eDate = "2014-06-05 16:10";
eDesc = "Pay \U00a350";
eEvent = "Victoria Center";
eLink = "http://linkedin.com";
eTitle = "Free movies";
},
{
"_id" = 53a8a41f360ce27c26c374f2;
eDate = "2014-06-05 16:10";
eDesc = "Pay \U00a350";
eEvent = "Victoria Center";
eLink = "http://linkedin.com";
eTitle = "Free movies";
}
但是,我想将所有这些放在一个数组中,如下所示:
"eventList": [
{
"_id" = 53a8a41c360ce27c26c374f1;
eDate = "2014-06-05 16:10";
eDesc = "Pay \U00a350";
eEvent = "Victoria Center";
eLink = "http://linkedin.com";
eTitle = "Free movies";
},
{
"_id" = 53a8a41f360ce27c26c374f2;
eDate = "2014-06-05 16:10";
eDesc = "Pay \U00a350";
eEvent = "Victoria Center";
eLink = "http://linkedin.com";
eTitle = "Free movies";
}
]
这就是我插入数据库的方式:
// Set our collection
var collection = db.get('Events');
// Submit to the DB
collection.insert({
"eTitle" : eTitle,
"eDesc" : eDesc,
"eDate" : eDate,
"eLink" : eLink,
"eEvent" : eEvent
}, function (err, doc) {
if (err) {
// If it failed, return error
res.send("There was a problem adding the information to the database.");
}
else {
res.location("eventlist");
// And forward to success page
res.redirect("eventlist");
}
});
请问我该如何解决这个问题?抱歉,对于node.js和mongodb来说非常棒!非常感谢