mongoose-history
mongoose-history copied to clipboard
Cannot nest schema if setup with plugin
Hi,
We have a collection which is configured with the history plugin and it works fine. However if I also embed the schema in another collection which also has the history plugin setup, then mongoose-history throws an error on save
TypeError: Cannot read property 'name' of undefined
at Document.<anonymous> (/xxx/app-name/node_modules/mongoose-history/lib/mongoose-history.js:31:79)
Basically, the save hook thinks that the subdocument also needs to be saved but it is part of a bigger document that has the history plugin setup.
One possible fix could be to check for this.collection
before trying to actually save.