const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/playground', { useUnifiedTopology: true }).then(() => console.log('数据库连接成功')).catch(err => console.log(err, '数据库连接失败'))//创建集合规则
const postSchema = new mongoose.Schema({title: {type: String,require: [true, '请传入文章标题'],minlength: 2,maxlength: 5,trim: true}
});
const Post = mongoose.model('Post', postSchema);
//插入数据
Post.create({}).then(result => console.log(result));