How to use entityQuery to find nodes with a specific multi-value field containing one specific value (and no others)? I have a node type "group" with an entity reference field "field_things" that can reference zero or more "thing" nodes. I'd like to use entityQuery to find all "groups" that have exactly one value for field_things, and that value is a specific "thing".

I can't tell from the docs how to combine those two requirements.
So it appears entityQuery() can't do this, but entityQueryAggregate() can. Below is an example that achieves the goal of the original post:

$thing_id = 101;
$q = \Drupal::entityQueryAggregate('node')
  -&gt;condition('type', 'group')
  -&gt;condition('field_things', $thing_id)
  -&gt;groupBy('nid')
  -&gt;conditionAggregate('field_things', 'COUNT', 1);
$res = $q-&gt;execute();


Running dpm($res) will show:

Array
(
  [0] =&gt; Array
    (
      [nid] =&gt; 85
      [field_things_count] =&gt; 1
    )

  [1] =&gt; Array
    (
      [nid] =&gt; 33
      [field_things_count] =&gt; 1
    )

  [2] =&gt; Array
    (
      [nid] =&gt; 57
      [field_things_count] =&gt; 1
    )

  [3] =&gt; Array
    (
      [nid] =&gt; 54
      [field_things_count] =&gt; 1
    )
)