# User search capabilities while using a Custom database connection

**URL:** <https://community.auth0.com/t/user-search-capabilities-while-using-a-custom-database-connection/11246>\
**Category:** Get Help\
**Tags:** user-search, custom-database\
**Created:** [May 1, 2018, 6:31am UTC](https://community.auth0.com/t/user-search-capabilities-while-using-a-custom-database-connection/11246 "2018-05-01T06:31:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sremella](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sremella/32/8655_2.png) [@sremella](https://community.auth0.com/u/sremella)\
**Post date:** [May 1, 2018, 6:31am UTC](https://community.auth0.com/t/user-search-capabilities-while-using-a-custom-database-connection/11246/1 "2018-05-01T06:31:54Z")

</div>

Hello,  
We expecting to use Auth0 for a multi-tenant SaaS application with a legacy user data store. We will be using a custom database connection to migrate users to Auth0 data store over time.

Our architecture relies on being able to retrieve users based on information stored in _metadata_ (as per [this article](https://auth0.com/docs/metadata) _app\_metadata_ should be named just _metadata_ if we are using a custom db connection).

Sample _metadata_

> {  
> “tenantId”: “bfc6b109-f668-44c2-bc8f-cf119a5b81e1”,  
> “groupCodes”: [  
> “csr”,  
> “admin”  
> ]  
> }

We need to retrieve users based on _tenantId_ or _groupCodes_ for different use cases. But the action scripts listed on [custom-db](https://auth0.com/docs/connections/database/custom-db) don’t seem to include anything for searching users.

Given that our users will span our custom db and Auth0 db for a period of time, we are looking for a consistent to perform these user searches, but I couldn’t find any documentation confirming the availability/unavailability of user search in case of custom db connections.

Could someone please clarify this for me?

---

<div class="post-metadata">

**Author:** ![sgmeyer](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/sgmeyer/32/3387_2.png) [@sgmeyer](https://community.auth0.com/u/sgmeyer)\
**Post date:** [May 1, 2018, 1:39pm UTC](https://community.auth0.com/t/user-search-capabilities-while-using-a-custom-database-connection/11246/2 "2018-05-01T13:39:45Z")

</div>

Hey there,

Unfortunately this isn’t easily achievable. Auth0 database action scripts for user import only expose `login` and `get_user` for specific user journeys. The `login` scripts are only called during authentication if there isn’t a user in Auth0 with a matching email or username. The `get_user` script is used for registration and forgot password flows, like login these scripts are only called when the user does not exist in Auth0 by email/username.

To search users in Auth0 you can use the management API, but this API will only search users in Auth0. It has no mechanism for reaching out to your user store container users that have not been migrated to Auth0.

The only way I can think about doing this is to utilize Auth0’s Management API to look for the user, if one isn’t found in Auth0 then issue a second search on your legacy user store (you would need to build this functionality). Because the users are not fully imported Auth0 will not have a way to search your users.

As an aside here are some best practices when using our search API: [User Search Best Practices](https://auth0.com/docs/users/search/best-practices#general-principles)

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 17, 2018, 10:40am UTC](https://community.auth0.com/t/user-search-capabilities-while-using-a-custom-database-connection/11246/3 "2018-12-17T10:40:17Z")

</div>


