📜  mongoose 将数据添加到集合 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:57.078000             🧑  作者: Mango

代码示例2
const Name =require('path of your model')
app.use('/path', (req,res,next)=>
{
    const firstName = req.body.firstName // req.body.firstName refers to your form name input
    const lastName = req.body.lastName // req.body.lastName refers to your form name input
    const nameData = new Name({firstName:firstName, lastName:lastName});
    nameData.save().then(res.redirect('/')).catch(err){
    console.log(err);
    };
});

//Remember to add a model
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const addittionSchema = new Schema({
    firstName:{
        type: String,
        required: True
    },
    lastName:{
        type: String,
        required:True
    }
});
module.exports = mongoose.model('budget', addittionSchema);