# We will use the new methods ReadPerference and not slaveOK. # You must have ran Replication_setup.txt and Replication_setup2.txt beforehand. echo ' function hi() { hinfo = db.runCommand("hostInfo")["system"]["hostname"]; print(hinfo); } hi(); print(db.no.count()); ' > mongo/hc.js # Only the primary will work both times. # We try to print the port and the count. # The count will fail on the rest, but the host and port will print. mongo --quiet --port 3001 mongo/hc.js mongo --quiet --port 3002 mongo/hc.js mongo --quiet --port 3003 mongo/hc.js mongo --quiet --port 3004 mongo/hc.js mongo --quiet --port 3005 mongo/hc.js mongo --quiet --port 3006 mongo/hc.js echo ' function hi() { hinfo = db.runCommand("hostInfo")["system"]["hostname"]; print(hinfo); } hi(); db.getMongo().setReadPref("primaryPreferred"); print(db.no.count()); ' > mongo/hc2.js # All should work but aritrary. Its data part should fail. mongo --quiet --port 3001 mongo/hc2.js mongo --quiet --port 3002 mongo/hc2.js mongo --quiet --port 3003 mongo/hc2.js mongo --quiet --port 3004 mongo/hc2.js mongo --quiet --port 3005 mongo/hc2.js mongo --quiet --port 3006 mongo/hc2.js