ramiel / mongoose-sequence

Sequence and autoincrement handling for mongoose

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wont work with .insertMany

thanhlmm opened this issue · comments

Like title, it wont work with .insertMany
Can you check it out?

I'll check out soon. Thank you for noticing this

Looks like the hooks called during insertMany are not useful to increment the counter (you can look Automattic/mongoose#3846). I'll look if there is another way to achieve this.

Meanwhile I added a test for this feature the you can find in this commit

Another reference here.
Following the discussion I believe you can use .create instead. It's slower than insertMany but calls the hook. The order is not garantueed to be the same as the documents definition, as explained at Automattic/mongoose#4038.
So if you have not a lot of insertions, or performance requirements, and the order can be not guaranteed, I suggest you to use .create. Let me know.

It's a nice solution. Thank you for checking it out.
Have a nice day!