How do I limit the number of rows affected from the query? In my custom module for Drupal 8, I am using the following code.

$query = $this-&gt;connection-&gt;select('node_field_data', 'nf_data');
$result = $query-&gt;execute();


I want to get the first 500 rows. I tried with $query-&gt;limit(50), but that gives the following error. 


  Call to undefined method Drupal\Core\Database\Driver\mysql\Select::limit() 


What is the correct code to get the first 500 rows?
See: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Database%21Query%21Select.php/class/Select/8.6.x

$query-&gt;range(0, 500);