Get all nodes with empty taxonomies I'm trying to fetch all nodes who's term reference field has no value or NULL.

$query = \Drupal::entityQuery('node')
    -&gt;condition('type', 'mycontenttype', '=')
    -&gt;condition('field_grade_level.entity.name', '');

    $nids = $query-&gt;execute();
    return $nids;


But it doesn't seem to work, giving empty results. Can anyone help what's wrong with the query?
You query is looking for nodes that are tagged with a term that has an empty label. Obviously that's not what you want. What you're looking for is notExists():

$query = \Drupal::entityQuery('node')
  -&gt;condition('type', 'mycontenttype', '=')
  -&gt;notExists('field_grade_level');

$nids = $query-&gt;execute();
return $nids;