Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential enhancement #5

Open
alexpchin opened this issue Jan 25, 2018 · 4 comments
Open

Potential enhancement #5

alexpchin opened this issue Jan 25, 2018 · 4 comments

Comments

@alexpchin
Copy link
Contributor

alexpchin commented Jan 25, 2018

Create an option to make the field uneditable? At the moment, you'd have to write custom logic to prevent people from sending the incremented field along with a request?

@nodkz
Copy link
Owner

nodkz commented Jan 25, 2018

Will be good improvement 👍

What name should have this option?
Do you have an example of custom logic which prevents changing?

@alexpchin
Copy link
Contributor Author

We should probably add a readonly: true option? I thought about just adding:

testSchema.path('count').set(function(value) {
    return this.count ? this.count : value;
});

However, this will prevent any editing at all. We could do something like:

counterSchema.path('count').set(function(value) {
    if (value - this.count !== settings.incrementBy) {
      return this.count ? this.count : value;
    } 
    return value;
});

Thoughts?

@nodkz
Copy link
Owner

nodkz commented Jan 25, 2018

It will not work with outputFilter option. So need to find other solution.

Somewhere here https://github.com/nodkz/mongoose-plugin-autoinc/blob/master/src/index.js#L315 we should add check on doc.isModified('counter') and then use doc.$ignore('counter') if readonly: true.

@sp3c1
Copy link
Contributor

sp3c1 commented Feb 23, 2018

To tell the truth its bit too much. no DB protectes you from updating the index that you autoincrement - ever. ^^

So I would vote on dropping this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants