Get node based target id from entity reference
We found the issue, it was both duplicate data issue and syntax errors mentioned by @berramou. The fix to the query was  changing -&gt;condition('status', 1); line to -&gt;condition('status', 1). 

We found that the test data included duplicate media entities so when the -&gt;condition('field_document', $linked_document_id, '='); was added, there were no results because the entities we were expecting were not in the table.

Sample test data:


media entity (id=1) name --> foo
media entity (id=2) name --> foo
media entity (id=3) name --> bar
Article->field_document->target_id = 1


I was expecting foo (id=1) to be returned but I was receiving foo (id=2). We have a specific requirement that media entities should be unique so after we merged the duplicate ones, the issue resolved. 

function mymodule_preprocess_node($variables) {
  $node = $variables['node'];
  $linked_document_id = $node-&gt;get('field_document')-&gt;first()-&gt;getValue()['target_id'];

  $node_storage = \Drupal::entityTypeManager()-&gt;getStorage('node');
  $query = $node_storage-&gt;getQuery()
    -&gt;condition('type', 'article')
    -&gt;condition('status', 1)
    -&gt;condition('field_document', $linked_document_id, '=');
  $results = $query-&gt;execute();

  // returns results now
  ksm($results);
}