How to get the media that owns a file? I have a file and I know there is a media that references it. How can I get this media?

In the opposite direction, knowing the media id, I can get the file:

$media = Media::load($mid);
$fid = $media-&gt;field_media_image-&gt;target_id;
$file = File::load($fid);


But now I know the file id and I want the media. How can I get it?
You can use entityQuery:

$fid = 13141;
$usedIn = \Drupal::entityQuery('media')
  -&gt;condition('field_media_image.target_id', $fid)
  -&gt;execute();


Example response:

Array
(
    [15105] =&gt; 13109
)