Welcome to the MongoDB Community Forums @Am_Ma!
The toArray() method in mongosh is a client-side method, so the reference to loading all documents into RAM is referring to fetching all matching documents from a query cursor into the local documentArray variable in your mongosh example.
For a large result set you will generally want to manually iterate the cursor and fetch smaller batches of documents for processing rather than retrieving the full result set.
For more information and examples, please see Iterate a Cursor in mongosh.
Regards,
Stennie