[英]Typescript Mongoose Custom Document Creation Methods
When using typescript with mongoose, how to write a method for saving / creating a document.使用 typescript 和 mongoose 时,如何编写保存/创建文档的方法。
Example: Contact entity contains phone number and name.示例:联系人实体包含电话号码和姓名。
ContactSchema.methods.createContact = async function (name: string, phoneNr: string) {
- custom controll flow
- creation of ducement???
}
ContactSchema.statics.createContact = async function (name: string, phoneNr: string) {
- your checks
return ContactSchema.create({ ... })
}
Was the best thing I come up with.是我想出的最好的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.