Skip to content

Commit

Permalink
Updated README to explain new incrementOnUpdate option.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Ford committed Sep 30, 2013
1 parent 3088e2a commit 3743746
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,25 @@ That's it. Now you can create book entities at will and the `_id` field will aut

### Want a field other than `_id`?

Let's say you have a field called `sortOrder` and you'd like to increment that instead of `_id`.
bookSchema.plugin(autoIncrement, { model: 'Book', field: 'sequence' });

bookSchema.plugin(autoIncrement, { model: 'Book', field: 'sortOrder' });
### Want that field to start at a different number than zero or increment by more than one?

Can't get much simpler than that!

### Want to start the field value at a different number than zero or increment by more than one?
bookSchema.plugin(autoIncrement, {
model: 'Book',
field: 'sequence',
startAt: 100,
incrementBy: 100
});

Let's say for some reason you want to start counting from 100 and you want to increment by 100 each time as well.
Your first book document would have an `_id` equal to `100`. Your second book document would have an `_id` equal to `200`, and so on.

bookSchema.plugin(autoIncrement, { model: 'Book', startAt: 100, incrementBy: 100 });
### Want your field to increment every time you update it too?

Your first book document would have an `_id` equal to `100`. Your second book document would have an `_id` equal to `200`, and so on.
bookSchema.plugin(autoIncrement, {
model: 'Book',
field: 'sequence',
startAt: 100,
incrementBy: 100,
incrementOnUpdate: true
});

0 comments on commit 3743746

Please sign in to comment.