You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem:
It is stated that we can use multiple history collections or one shared collection for the history schemas. However, it is not possible to use a shared collection to hold the history of more than one schema. A mongoose OverwriteModelError is thrown when using the plugin on multiple schemas with the same modelName.
Possible Solution:
After looking at the code, it seems that no check is performed to see if the model already exists before creating it. As a temporary fix, I changed the code to this:
...
let mongoose = pluginOptions.mongoose;
const collectionIdType = options.collectionIdType || mongoose.Schema.Types.ObjectId;
let Model;
try { // Check if the model exists
Model = mongoose.model(pluginOptions.modelName);
} catch (e) {}
if (!Model) {
... // schema code
Model = mongoose.model(pluginOptions.modelName, Schema);
}
...
That seemed to fix the issue. Can you please make a new release with a similar fix? Thanks for the great plugin!
The text was updated successfully, but these errors were encountered:
Problem:
It is stated that we can use multiple history collections or one shared collection for the history schemas. However, it is not possible to use a shared collection to hold the history of more than one schema. A mongoose OverwriteModelError is thrown when using the plugin on multiple schemas with the same modelName.
Possible Solution:
After looking at the code, it seems that no check is performed to see if the model already exists before creating it. As a temporary fix, I changed the code to this:
That seemed to fix the issue. Can you please make a new release with a similar fix? Thanks for the great plugin!
The text was updated successfully, but these errors were encountered: