ramiel/mongoose-sequence

Counter already defined for field "seq"

Closed this issue · 3 comments

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"

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.

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

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.