I tried Using the mongoose-unique-validator module, it's working when I create a user with the same username with different cases like 'username' & 'USErName'. the problem is when I try to login with one of them I get a bad request. if there is any other solution besides this module. Thanks in advance.
The most common solution when you want to allow the user to have what is called display name is to have an extra field in the collection to store that and ALWAYS normalize the username field (nickname in your case) by converting it to lowercase characters.
This way, if you need to display that info you use the displayName field, but when a user is trying to authenticate you get the input data and lowercase it before checking for it in the database.
By using that approach you might not even need that extra dependency.