const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/playground', { useUnifiedTopology: true }).then(() => console.log('数据库连接成功')).catch(err => console.log(err, '数据库连接失败'))//创建集合规则
const courseSchema = new mongoose.Schema({name: String,age: Number,email: String,password: String,hobbies: [String]
});
//使用集合并应用规则
const User = mongoose.model('User', courseSchema);
//查找到一条文档并且删除
User.findOneAndDelete({ _id: '5c09f1e5aeb04b22f8460965' }).then(result => console.log(result));
//删除多条数据
User.deleteMany({}).then(result => console.log(result));
运行结果