I am trying to run periodically a somehow heavy script in a mongo replica set.
As we are not using secondaries for read operations, I'd like to execute it against a secondary.
So I have a js script that can be executed in mongo shell like this :
mongo <replica_name>/host1:port1,host1:port2/<dbname> <my_script.js>
Inside my script I have :
db.getMongo().setReadPref('secondary');
Is this enough to ensure I will be executing against a secondary?
For instance if I execute
mongo <replica_name>/host1:port1,host1:port2/<dbname>
I get a prompt that says I am in the primary
rs_name:PRIMARY> db.getMongo().setReadPref('secondary');
rs_name:PRIMARY> db.getMongo()
connection to rs_name/localhost:27117,localhost:27127
So I don't know where my read operations are going to be executed.
Any ideas??