public void putRecipeSummary(RecipeSummary recipeSummary) { MongoCollection<BsonDocument> collectionRecipeSummary = database.getCollection("recipeSummary", BsonDocument.class); BsonDocument bsonDocument = BsonDocument.parse(recipeSummary.toJson()); bsonDocument.put("_id", new BsonString(recipeSummary.getRecipeId())); LOG.info("put bsonDocument = {}", bsonDocument.toString()); collectionRecipeSummary.replaceOne( eq("_id", recipeSummary.getRecipeId()), bsonDocument, new UpdateOptions().upsert(true)); // collectionRecipeSummary.insertOne(bsonDocument); }
public RecipeSummary getRecipeSummary(String recipeId) { MongoCollection<BsonDocument> collectionRecipeSummary = database.getCollection("recipeSummary", BsonDocument.class); BsonDocument document = collectionRecipeSummary.find(eq("_id", recipeId)).first(); if (document != null) { LOG.info("get document = {}", document.toString()); return new RecipeSummary().fromJson(document.toJson()); } else { LOG.info("Null Document for recipeId={}", recipeId); return null; } }