I think you may be misunderstanding the use case for setting read preferences. You would set this read preference before running commands or queries via the same connection.
mongo --port <secondaty_node_port> --eval “rs.slaveOk()”
The outcome of this would be mongo shell attempting to connect to your secondary on localhost and the specified port, running the JavaScript code in --eval, and then exiting. Setting the read preference for the current session has no effect on future sessions.
Can you share more details on what you are trying to achieve? It sounds like perhaps you are trying to Write Scripts for the mongo Shell.
Regards,
Stennie