How to write a Mongoose model in ES6 / ES2015

前端 未结 7 1939
自闭症患者
自闭症患者 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:13

    This will work:

    import mongoose from 'mongoose';
    
    const { Schema } = mongoose;
    const userSchema = new Schema({
    
      email: {
          type: String,
          required: true
      },
      firstName: {
          type: String,
      },
      lastName: {
          type: String
      },
      age: {
          type: Number
      }
    });
    
    export default mongoose.model('User', userSchema);
    

提交回复
热议问题