When Mongo.setReadPref('secondary') is called from the mongo shell when connected to a secondary, an aggregate with $out/$merge errors with 'NotMasterNoSlaveOk' and doesn't run. The only way to get this to work is to use the legacy 'Mongo.setSlaveOk(true)'.
Update Mongo.setReadPref() to respect the specified readPreference.