mongoose-plugin-autoinc icon indicating copy to clipboard operation
mongoose-plugin-autoinc copied to clipboard

How to implement autoinc in existing project?

Open arso1er opened this issue 7 years ago • 2 comments

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.

arso1er avatar Jan 28 '18 21:01 arso1er

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.

nodkz avatar Jan 29 '18 09:01 nodkz

OK, thanks for the answer.

arso1er avatar Jan 29 '18 09:01 arso1er