Johnwickdev / Hightable

0 stars 0 forks source link

Update #77

Open Johnwickdev opened 2 months ago

Johnwickdev commented 2 months ago

private void updateMongoDBCollection(Document updatedDoc) { try (var mongoClient = MongoClients.create(mongoConfig.getUri())) { MongoDatabase database = mongoClient.getDatabase(mongoConfig.getDatabase()); MongoCollection actualCollection = database.getCollection(mongoConfig.getActualCollection());

    // Update based on a unique identifier (e.g., CSPA, version, layout_name)
    Document filter = new Document("CSPA", updatedDoc.getString("CSPA"))
                           .append("version", updatedDoc.getString("version"))
                           .append("layout_name", updatedDoc.getString("layout_name"));

    // Replace the document if it exists, or insert it if it doesn't
    actualCollection.replaceOne(filter, updatedDoc, new ReplaceOptions().upsert(true));
} catch (Exception e) {
    e.printStackTrace();
}

}