# Username does not work for custom mongodb connection

**URL:** <https://community.auth0.com/t/username-does-not-work-for-custom-mongodb-connection/57637>\
**Category:** Get Help\
**Tags:** mongodb, username, login\
**Created:** [February 10, 2021, 2:20am UTC](https://community.auth0.com/t/username-does-not-work-for-custom-mongodb-connection/57637 "2021-02-10T02:20:12Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![sgo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgo/32/13789_2.png) [@sgo](https://community.auth0.com/u/sgo)\
**Post date:** [February 27, 2021, 9:39am UTC](https://community.auth0.com/t/username-does-not-work-for-custom-mongodb-connection/57637/2 "2021-02-27T09:39:18Z")

</div>

Hi @raalrwai ,

The sample template is assuming you are using emails only, not usernames.

When you enable “Requires Username”, you will need to add additional logic to your Custom DB scripts to be able to handle the `email` parameter being passed as either an email or a username, and be able to find the user correctly with either. In both cases, it should return the same profile, including the username in said profile so it can be stored in Auth0 (for import mode).

This is mentioned in the [docs](https://auth0.com/docs/connections/database/custom-db/templates/get-user):

> The email address for the user as the user identifying credential. If **Requires Username** is enabled for your connection, the **Get User** script may run multiple times for some transactions (ex. Creating a user, or requesting a password reset link). In these cases the value of the parameter will sometimes be a username instead of an email. Your code should be able to handle either value and always return the same profile for a given user regardless of whether they were looked up by email or username.

You may find using an [$or operator](https://docs.mongodb.com/manual/reference/operator/query/or/) to carry out the search for the “email” parameter in `email` or `username` useful if either can be used in your use case: [node.js - Mongodb findOne with or - Stack Overflow](https://stackoverflow.com/a/27647261)

---

_[View the full topic](https://community.auth0.com/t/username-does-not-work-for-custom-mongodb-connection/57637)._
