Unable to check existence of a field

I have a field in app_metadata with empty array as value.
When I try to search users by using _exists_ for that field, it doesn’t return any users. Only when I put a value inside that array or just replace the empty array with an actual integer or string value, api starts returning that user. There are a lot of users, is there an alternate way to check existence of a property in app_metadata ?

Hi @puneet ,

Welcome to the Auth0 Community!

I tried on my end and observed the same. We can query a field in app_metadata/user_metadata that stores an empty string but not an empty array. I have reached out to our internal team and will get back to you soon.

Due to product limitations, we can’t search for empty arrays or check for array items count.

Alternatively, you can include another metadata field to store the number of items in the array. When updating the array, this new field will also need to be updated. And you can query this field to find the users.

Is this something you want to consider?

app_metadata: {
   key1: [],
   key2: {
        key3: []
   }
}

Even if I look for key2, it doesn’t return anything because key3 has empty array in it, I don’t think this is the correct way to handle this scenario and Auth0 should fix this. Currently, I am going to change the way I store metadata and add some default non empty value so that it gets picked up by the search API call.

Will Auth0 be fixing this bug in the near future?

@puneet @sergey2

I understand your concerns and have passed your feedback to our Engineering team. Once the information is available, I will post the details on this topic. Thank you!

@puneet @sergey2 ,

Here are updates we just received:

Currently, we do not index null, empty array ([]), and empty objects ({}) fields in metadata (user_metadata or app_metadata). These fields are currently treated as if they don’t exist by the search backend, so to retrieve the user mentioned in your question, the customer could emit such a query:

q:NOT _exists_:app_metadata.key1

Note that in addition to returning users with key1: [], this would also return users who do not have key1 in their app_metadata.

Moreover, the existence queries can be very slow and may timeout depending on the size of the user base of the customer. For that reason, we don’t recommend using them in our https://auth0.com/docs/manage-users/user-search/user-search-best-practices .

For the scenario you described, a better way would be to search for another attribute in metadata. For example, set a key1_empty: true flag in your metadata object to identify users having key1: []. This would allow us to retrieve the user much more efficiently from the user search endpoint.

Our Documentation team added below in this doc to reflect this limitation.

Metadata fields that contain an empty array, empty object, or null value are not indexed and cannot be searched for.

I have created a feature request ticket for handling this concern in the future.

Any other queries regarding this topic I can assist?

1 Like