ramiel / mongoose-sequence

Sequence and autoincrement handling for mongoose
GNU General Public License v2.0
283 stars 56 forks source link

Counter already defined for field "seq" #122

Closed Karman40 closed 2 years ago

Karman40 commented 2 years ago

Hello,

I'm using NestJS and I get the following error message every time hot-reload reload the app:

[Nest] 20384  - 2022. 03. 29. 19:21:02   ERROR [ExceptionHandler] Counter already defined for field "seq"
Error: Counter already defined for field "seq"
viztheman commented 2 years ago

This was giving me fits, too. Adding the {id: 'UniqueSequenceNameHere'} option to schema.plugin() seems to have fixed it.

I think at some point that property went from optional to required, even on simple fields. Don't really know though.

Karman40 commented 2 years ago

I ended up writing my own script. Anyway, I suspect this won't close the connection (from mongoDB) when the app reload.

ramiel commented 2 years ago

Yes @viztheman, even if the property is technically optional, it's safer to be specified. For example, if for some reason NextJS call the plugin twice, it becomes mandatory.