這是我的架構使用Mongoose和Node將數據插入數組時出錯?
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var FoodSchema = new mongoose.Schema({
title: String,
comments: [{
text: String
}]
});
module.exports = mongoose.model('Food', FoodSchema);
如何張貼在評論中值,我已經試過這
router.route('/food')
.post(function(req, res) {
var food = new Food();
food.title = req.body.title;
food.comments.text= req.body.comments[0].text;
food.save(function(err) {
if (err)
res.send(err);
res.json({ message: 'Successful'});
});
}) ;
標題被插入,而不是評論
是的,它工作! :) thanx – MrRobot9