How to get rid of Error: “OverwriteModelError: Cannot overwrite `undefined` model once compiled.”?

后端 未结 6 1820
太阳男子
太阳男子 2021-02-05 07:34

I have a common method for updating document of any collection in MongoDB?

The following code is in file name Deleter.js

module.exports         


        
6条回答
  •  伪装坚强ぢ
    2021-02-05 08:16

    I managed to resolve the problem like this:

    var Admin;
    
    if (mongoose.models.Admin) {
      Admin = mongoose.model('Admin');
    } else {
      Admin = mongoose.model('Admin', adminSchema);
    }
    
    module.exports = Admin;
    

提交回复
热议问题