📜  mongoose express js post - Javascript代码示例

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

代码示例1
const express = require("express");
const route = express.Router();
const mongoose = require("mongoose");
const Schema = mongoose.Schema;

const noteSchema = new Schema({
    note: {
        type: String,
        required: true
    },

});
const noteModels = mongoose.model("note", noteSchema);

route.post("/", async (req, res) => {
    const note = new noteModels({
      note: req.body.note,
    });

    const saveNote = await note.save();
    res.json(saveNote);
  })
 
module.exports = route;