class RefreshOperation implements MongoDbOperation {

    @Override
    public void execute(final MongoDatabase connection, final Document data) {
        for (final String collectionName : data.keySet()) {
            final MongoCollection<Document> collection = connection.getCollection(collectionName);

            @SuppressWarnings("unchecked")
            final List<Document> documents = data.get(collectionName, List.class);

            for (final Document doc : documents) {
                final UpdateResult result = collection.replaceOne(Filters.eq(doc.get("_id")), doc);

                if (result.getMatchedCount() == 0) {
                    collection.insertOne(doc);
                }
            }
        }
    }

}