code: public MongoCredential withMechanism(final AuthenticationMechanism mechanism) {
          if (this.mechanism != null) {
              throw new IllegalArgumentException("Mechanism already set");
          }
          return new MongoCredential(mechanism, userName, source, password, mechanismProperties);
      }
docs: Creates a new MongoCredential with the set mechanism. The existing mechanism must be null.
  
  @param mechanism the mechanism to set
  @return the credential
  @since 3.8