我有一個更新MongoDB中任何集合的文檔的常用方法?如何擺脫錯誤:「OverwriteModelError:一旦編譯就無法覆蓋`undefined`模型。」?
下面的代碼是在文件名Deleter.js
module.exports.MongooseDelete = function (schemaObj, ModelObject);
{
var ModelObj = new mongoose.Model("collectionName",schemaObj);
ModelObj.remove(ModelObject);
}
並調用在我的主文件如下app.js:
var ModObj = mongoose.model("schemaName", schemasObj);
var Model_instance = new ModObj();
var deleter = require('Deleter.js');
deleter.MongooseDelete(schemasObj,Model_instance);
我收到以下錯誤:
OverwriteModelError: Cannot overwrite `undefined` model once compiled.
at Mongoose.model (D:\Projects\MyPrjct\node_modules\mongoose\lib\index.js:4:13)
我只有第二個方法調用.. 請讓我知道是否有任何人有一些解決方案。
什麼是你想用'MongooseDelete'辦?爲什麼不直接調用'Model_instance.remove();'? – JohnnyHK
我只是試圖使刪除調用一個常用的方法,在我的自定義模塊..即使我調用MongooseDelete(/ * params */n次提供如果架構是相同的,我的工作原理,當我嘗試刪除不同的文檔架構,我收到以上錯誤消息。感謝您對回答的好感... –
難道你不能改變'MongooseDelete'來調用'ModelObject.remove();'? – JohnnyHK