lucid-mongo icon indicating copy to clipboard operation
lucid-mongo copied to clipboard

Probably wrong unique validator ignore check

Open erisrayanesh opened this issue 5 years ago • 1 comments

Im not very expert in mongodb but I would like to know how this line applies a whereNotEqual on query. Because I think it means where the ignoreKey has a value greater than ignoreValue. Doesn't this has a special meaning for numeric or some other data types?

https://github.com/duyluonglc/lucid-mongo/blob/04d614feb3fdc9714d8fe73bdc617d021e9dec2d/src/Validator/index.js#L72

How about objectId fields like _id or a foreign key like user_id? How to tell the validator that the ignoreValue is an ObjectId field?

After many many tests, now I'm pretty sure that the above code is wrong and has to be replaced with something like below code

query.where(ignoreKey, '<>', ignoreValue)

erisrayanesh avatar Jul 27 '19 18:07 erisrayanesh

@erisrayanesh you are right, It should be '<>' instead. Can you make PR to fix it?

duyluonglc avatar Jul 28 '19 00:07 duyluonglc