How to write a Mongoose model in ES6 / ES2015

前端 未结 7 1957
自闭症患者
自闭症患者 2021-02-18 23:55

I want to write my mongoose model in ES6. Basically replace module.exports and other ES5 things wherever possible. Here is what I have.

import mongo         


        
7条回答
  •  盖世英雄少女心
    2021-02-19 00:03

    To do things the ES6, class-like way, as the question states, I simply had to invoke the class with new in the exported mongoose.model function.

    export default mongoose.model('Blacklist', new Blacklist)
    

提交回复
热议问题