I have a common method for updating document of any collection in MongoDB?
The following code is in file name Deleter.js
module.exports.MongooseDelete = function (schemaObj, ModelObject); { var ModelObj = new mongoose.Model("collectionName",schemaObj); ModelObj.remove(ModelObject); }
And invoking as follows in my main file app.js:
var ModObj = mongoose.model("schemaName", schemasObj); var Model_instance = new ModObj(); var deleter = require('Deleter.js'); deleter.MongooseDelete(schemasObj,Model_instance);
I am getting following error:
OverwriteModelError: Cannot overwrite `undefined` model once compiled. at Mongoose.model (D:\Projects\MyPrjct\node_modules\mongoose\lib\index.js:4:13)
I get on 2nd method call only.. Please let me know if any one has got some solution.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With