1.remove删除所有匹配的document
const mongoose = require('mongoose');
mongoose.connect( 'mongodb://127.0.0.1:27017/eggcms', {useNewUrlParser: true});
var UserSchema =new mongoose.Schema({
name:String,
age:Number
})
var User = mongoose.model('User',UserSchema,'user')
User.remove({name:"chengchao"},(err,doc)=>{
if(err) throw err;
console.log(doc)
})
2.deleteOne删除一条document
/* 1.引入mongoose */
const mongoose = require('mongoose');
/* 2.连接数据库 */
mongoose.connect( 'mongodb://127.0.0.1:27017/eggcms', {useNewUrlParser: true});
/* 3.操作user表(集合),定义一个schema */
;
var UserSchema =new mongoose.Schema({
name:String,
age:Number
})
var User = mongoose.model('User',UserSchema,'user')
User.deleteOne({name:"chengchao"},(err,doc)=>{
if(err) throw err;
console.log(doc)
})