How to do an EntityQuery on a custom User field? I'm having trouble figuring out how to use the EntityQuery on custom field values. As an example I have a custom field under the User bundle that stores the country in which the user lives. There are three options: US, Canada and Mexico. I'd like to use the EntityQuery to directly query the 'field_country' to get a count of how many live in one country and get their uids. Here is an export from the database for this field:



The closest I've gotten is the code snippet below. This however is not working and I'm not sure where to go from here.

$results = \Drupal::entityQuery('user')
      -&gt;condition('field_country', 'Canada')
      -&gt;execute();


Does anybody know? Does the entityquery give me the ability to look specific columns in a field? Thanks!

P.S. I know I could do this with a database query but I'd prefer to do it the Drupal way.
I think you might be missing a line:

$ids = \Drupal::entityQuery('user')
  -&gt;condition('field_country', 'Canada')
  -&gt;execute(); // This returns the user ids

// Load the users
$users = User::loadMultiple($ids);
foreach ($users as $uid =&gt; $user) {
    // $user contains the $user entity
}


More examples are located on the docs page.