class MongoDbMetadataRepository {

    public void insert(List<T> metadataDocuments) throws MetaDataExecutionException {

        BulkWriteOptions options = new BulkWriteOptions();
        options.ordered(false);

        try {
            List<InsertOneModel<T>> collect = new ArrayList<>();
            metadataDocuments.forEach(metadataDocument -> {
                metadataDocument.append(VERSION, 0);
                metadataDocument.append(ATOMIC_VERSION, 0);
                metadataDocument.append(TENANT_ID, ParameterHelper.getTenantParameter());
                InsertOneModel<T> tInsertOneModel = new InsertOneModel<>(metadataDocument);
                collect.add(tInsertOneModel);
            });
            BulkWriteResult bulkWriteResult = mongoCollectionSupplier.get().bulkWrite(collect, options);
            if (bulkWriteResult.getInsertedCount() != metadataDocuments.size()) {
                throw new MetaDataExecutionException(
                    String.format("Error while bulk save document count : %s != size : %s :",
                        bulkWriteResult.getInsertedCount(), metadataDocuments.size()));
            }
        } catch (final MongoBulkWriteException e) {

            boolean hasBlockerErrors = false;
            for (BulkWriteError bulkWriteError : e.getWriteErrors()) {
                if (bulkWriteError.getCategory() == ErrorCategory.DUPLICATE_KEY) {
                    LOGGER.warn("Document already exists " + metadataDocuments.get(bulkWriteError.getIndex()).getId() + ". Ignoring quietly (idempotency)");
                } else {
                    hasBlockerErrors = true;
                    LOGGER.error("An error occurred during metadata insert " + bulkWriteError);
                }
            }
            if(hasBlockerErrors) {
                throw new MetaDataExecutionException(e);
            }
        } catch (final MongoException | IllegalArgumentException e) {
            throw new MetaDataExecutionException(e);
        }
    }

    public  MongoDbMetadataRepository(Supplier<MongoCollection<T>> mongoCollectionSupplier);

}