const express = require('express');const router = express.Router();const mongoose = require('mongoose');const _ = require('underscore');let sampleSchema = new mongoose.Schema({ name: { type: 'String', unique: true }, tags: [{ type: 'String' }]})sampleSchema.pre('save', function (next) { this.tags = _.uniq(this.tags); next();});const Sample = mongoose.model('sample', sampleSchema, 'samples');router.post('/sample', function (req, res, next) { const sample = new Sample(req.body); sample.save() .then((sample) => { return res.send(sample); }) .catch(err => { return res.status(500).send(err.message); })});
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)