ReadPreference getCommandReadPreference(DBObject command, ReadPreference requestedPreference){
        if (_mongo.getReplicaSetStatus() == null) {
            return requestedPreference;
        }

        String comString = command.keySet().iterator().next();

        if (comString.equals("getnonce") || comString.equals("authenticate")) {
            return ReadPreference.primaryPreferred();
        }

        boolean primaryRequired;

        // explicitly check mapreduce commands are inline
        if(comString.equals("mapreduce")) {
            Object out = command.get("out");
            if (out instanceof BSONObject ){
                BSONObject outMap = (BSONObject) out;
                primaryRequired = outMap.get("inline") == null;
            } else {
                primaryRequired = true;
            }
        } else if(comString.equals("aggregate")) {
            @SuppressWarnings("unchecked")
            List<DBObject> pipeline = (List<DBObject>) command.get("pipeline");
            primaryRequired = pipeline.get(pipeline.size()-1).get("$out") != null;
        } else {
           primaryRequired =  !_obedientCommands.contains(comString.toLowerCase());
        }

        if (primaryRequired) {
            return ReadPreference.primary();
        } else if (requestedPreference == null) {
            return ReadPreference.primary();
        } else {
            return requestedPreference;
        }
    }