0
我想動態呈現貓鼬模型並通過UI編輯字段,因此我需要覆蓋mongoode模型。我收到以下錯誤:如何覆蓋貓鼬模型?
OverwriteModelError: Cannot overwrite `[MODEL NAME]` model once compiled.
如果我刪除架構屬性和模型對象
for (modelName in that.innstance.models) {
// deletes the mongoose models and schema
delete mongoose.models[modelName];
delete mongoose.modelSchemas[modelName];
delete app.models[modelName];
}
我能夠但是再次註冊模型,當我創建一個模型對象我凸輪只通過MODEL._doc.some_field
訪問屬性,而不是MODEL.some_field
爲什麼不立即編譯模型,只要你知道它將會是什麼? – Gant
它是動態的。我需要能夠在飛行中改變它。 –
@AryehArmon你已經注意到了,貓鼬對於這樣的工作並不是真正的工具(儘管我不會直接知道一個替代方案)。 – robertklep