mongoose-plugin-autoinc
mongoose-plugin-autoinc copied to clipboard
How to implement autoinc in existing project?
Hi, I'm using autoinc in a new project and so far, it's working very well. Now, I'd like to use autoinc in an existing project of mine; could you tell me how to apply autoinc to already existing entries in my database?
Thanks.
It's not automated, so you can do this manually:
- Manually set values for your existed records.
- Then define plugin with
startAt
option:BookSchema.plugin(autoIncrement, { model: 'Book', field: 'bookId', startAt: __YOUR_LAST_NUMBER__ });
PS. will be awesome if somebody makes a PR with helper function for collection, eg. rewriteAutoIncrement()
, which traverse all existed records and re-writes ids.
OK, thanks for the answer.