@Override
    public void upgrade() {
        if (clusterConfigService.get(V20230531135500_MigrateRemoveObsoleteItemsFromGrantsCollection.MigrationCompleted.class) != null) {
            return;
        }

        final Set<String> names = new HashSet();
        mongoConnection.getMongoDatabase().listCollectionNames().forEach(names::add);

        if (names.contains(DBGrantService.COLLECTION_NAME)) {
            var query = new BasicDBObject("target", Pattern.compile("^grn::::favorite:"));
            mongoConnection.getMongoDatabase().getCollection(DBGrantService.COLLECTION_NAME).deleteMany(query);
            query = new BasicDBObject("target", Pattern.compile("^grn::::last_opened:"));
            mongoConnection.getMongoDatabase().getCollection(DBGrantService.COLLECTION_NAME).deleteMany(query);
        }

        clusterConfigService.write(new MigrationCompleted());
    }
@Test
    @MongoDBFixtures("V20230531135500_MigrateRemoveObsoleteItemsFromGrantsCollectionTests.json")
    void removingAllObsoleteEntries() {
        assertThat(this.collection.countDocuments()).isEqualTo(13);

        this.migration.upgrade();

        assertThat(migrationCompleted()).isNotNull();
        assertThat(this.collection.countDocuments()).isEqualTo(9);

        this.collection.find().forEach(d -> {
            assertThat(d.get("target").toString()).doesNotContain("favorite");
            assertThat(d.get("target").toString()).doesNotContain("last_opened");
        });
    }