EntityQuery condition for multivalue fields I need to select some entities that have a certain field (user reference) empty or that field does not contain the current user as a reference. 

I tried this, it works ok if the field is empty or if the field contains exactly one value. For multiple values it displays a wrong output:

$query = $this-&gt;entityTypeManager()-&gt;getStorage('my_entity_type')-&gt;getQuery();
$group = $query-&gt;orConditionGroup()-&gt;notExists("my_field")-&gt;condition("my_field", \Drupal::currentUser()-&gt;id(), "&lt;&gt;");
$query-&gt;condition($group);
$query-&gt;condition("type", "my_bundle_id");

$ids = $query-&gt;sort(...)-&gt;execute();


Any thoughts on how to make this work?
Try to use NOT IN instead of &lt;&gt;.

-&gt;condition("my_field", [\Drupal::currentUser()-&gt;id()], "NOT IN");


You can learn more here.