@Override
    public void upgrade() {
        final FindIterable<Document> documentsWithMissingFields = collection.find(or(not(exists(ContentPack.FIELD_META_ID)), not(exists(ContentPack.FIELD_META_REVISION))));
        for (Document document : documentsWithMissingFields) {
            final ObjectId objectId = document.getObjectId("_id");
            LOG.debug("Found document with missing \"id\" or \"rev\" field with ID <{}>", objectId);
            final String id = document.get("id", objectId.toHexString());
            final int rev = document.get("rev", 0);

            document.put("id", id);
            document.put("rev", rev);

            final UpdateResult updateResult = collection.replaceOne(eq("_id", objectId), document);

            if (updateResult.wasAcknowledged()) {
                LOG.debug("Successfully updated document with ID <{}>", objectId);
            } else {
                LOG.error("Failed to update document with ID <{}>", objectId);
            }
        }
    }
@Test
    @MongoDBFixtures("V20180718155800_AddContentPackIdAndRevTest.json")
    public void upgrade() {
        final MongoCollection<Document> collection = mongodb.mongoConnection()
                .getMongoDatabase()
                .getCollection(ContentPackPersistenceService.COLLECTION_NAME);
        final Bson filter = and(exists(ContentPack.FIELD_META_ID), exists(ContentPack.FIELD_META_REVISION));

        assertThat(collection.countDocuments(filter)).isEqualTo(1L);
        migration.upgrade();
        assertThat(collection.countDocuments(filter)).isEqualTo(2L);
    }