protected final FluentFuture<Optional<T>> doReplace(
            final Constraints.ConstraintHost criteria,
            final T document,
            final FindOneAndReplaceOptions options) {

      checkNotNull(criteria, "criteria");
      checkNotNull(document, "document");
      checkNotNull(options, "options");

      return submit(new Callable<Optional<T>>() {
        @Override
        public Optional<T> call() throws Exception {
          @Nullable T result = collection().findOneAndReplace(
              convertToBson(criteria), // query
              document,
              options);

          return Optional.fromNullable(result);
        }
      });

    }
Codec used for current collection type.
@return registry
mongo/src/org/immutables/mongo/repository/Repositories.java