1. mongoose
Built-in CURD
official website address
Model.deleteMany()
Model.deleteOne()
Model.find()
Model.findById()
Model.findByIdAndDelete()
Model.findByIdAndRemove()
Model.findByIdAndUpdate()
Model.findOne()
Model.findOneAndDelete()
Model.findOneAndRemove()
Model.findOneAndReplace()
Model.findOneAndUpdate()
Model.replaceOne()
Model.updateMany()
Model.updateOne()
Two, schema
extend the static method yourself
-
1.
schema
Extend static methods inUserSchema.statics.findByName = function(name, callback) { this.findOne({ name}, (err, docs) => { callback(err, docs); }) }
-
2. Use static methods
UserModel.findByName('张三', (err, docs) => { console.log(docs); })
Three, schema
extend the instance method yourself
The so-called instance method is similar to the
save
function when creating data
-
1.
schema
Extend the example method in (the project is less used)// 扩展实例方法 UserSchema.methods.print = function(){ console.log(this, '实例方法'); }
-
2. Use custom instance methods
var user = new UserModel({ name: ' 李四 ', age: 20, message1: 'hello', message2: 'word' }); user.print();