通过猫鼬将项目推入mongo数组
people: { name: String, friends: [{firstName: String, lastName: String}] }
db.people.update({name: "John"}, {$push: {friends: {firstName: "Harry", lastName: "Potter"}}});
最新情况:
app.get('/addfriend', users.addFriend);
exports.addFriend = function (req, res, next){var friend = {"firstName": req.body.fName, "lastName": req.body.lName};Users.findOneAndUpdate({name: req.user.name}, {$push: {friends: friend}});};
米琪卡哇伊
饮歌长啸