[英]Assign custom methods in mongoose .d.ts so I can use them anywhere with mongoose in typescript
[英]Typescript Mongoose Custom Document Creation Methods
使用 typescript 和 mongoose 時,如何編寫保存/創建文檔的方法。
示例:聯系人實體包含電話號碼和姓名。
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({ ... })
}
是我想出的最好的東西。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.