protected final FluentFuture<Integer> doUpsert(
        final Constraints.ConstraintHost criteria,
        final T document) {
      checkNotNull(criteria, "criteria");
      checkNotNull(document, "document");
      return submit(new Callable<Integer>() {
        @Override
        public Integer call() {
          collection().replaceOne(convertToBson(criteria), document, new ReplaceOptions().upsert(true));
          // upsert will always return 1:
          // if document doesn't exists, it will be inserted (modCount == 1)
          // if document exists, it will be updated (modCount == 1)

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