protected final FluentFuture<Integer> doUpdate(
final Constraints.ConstraintHost criteria,
final Constraints.Constraint update,
final UpdateOptions options) {
checkNotNull(criteria, "criteria");
checkNotNull(update, "update");
checkNotNull(options, "options");
return submit(new Callable<UpdateResult>() {
@Override
public UpdateResult call() {
return collection()
.updateMany(
convertToBson(criteria),
convertToBson(update),
options);
}
}).lazyTransform(new Function<UpdateResult, Integer>() {
@Override
public Integer apply(UpdateResult input) {
return (int) input.getModifiedCount();
}
});
}
java类com.mongodb.client.result.UpdateResult的实例源码
Repositories.java 文件源码
项目:GitHub
阅读 43
收藏 0
点赞 0
评论 0
UpdateDocumentsImpl.java 文件源码
项目:mongodb-crud
阅读 33
收藏 0
点赞 0
评论 0
/**
* This method update all the matches document
*/
@Override
public void updateManyDocument() {
MongoDatabase db = null;
MongoCollection collection = null;
Bson filter = null;
Bson query = null;
try {
db = client.getDatabase(mongo.getDataBase());
collection = db.getCollection(mongo.getSampleCollection());
filter = eq("name", "Sundar");
query = combine(set("age", 23), set("gender", "Male"));
UpdateResult result = collection.updateMany(filter, query);
log.info("UpdateMany Status : " + result.wasAcknowledged());
log.info("No of Record Modified : " + result.getModifiedCount());
} catch (MongoException e) {
log.error("Exception occurred while update Many Document : " + e, e);
}
}
UpdateDocumentsImpl.java 文件源码
项目:mongodb-crud
阅读 32
收藏 0
点赞 0
评论 0
/**
* This method update document with lastmodified properties
*/
@Override
public void updateDocumentWithCurrentDate() {
MongoDatabase db = null;
MongoCollection collection = null;
Bson filter = null;
Bson query = null;
try {
db = client.getDatabase(mongo.getDataBase());
collection = db.getCollection(mongo.getSampleCollection());
filter = eq("name", "Sundar");
query = combine(set("age", 23), set("gender", "Male"),
currentDate("lastModified"));
UpdateResult result = collection.updateOne(filter, query);
log.info("Update with date Status : " + result.wasAcknowledged());
log.info("No of Record Modified : " + result.getModifiedCount());
} catch (MongoException e) {
log.error("Exception occurred while update Many Document with Date : " + e, e);
}
}
MongodbManager.java 文件源码
项目:grain
阅读 26
收藏 0
点赞 0
评论 0
/**
* 修改记录
*
* @param collectionName
* 表名
* @param mongoObj
* 对象
* @return
*/
public static boolean updateById(String collectionName, MongoObj mongoObj) {
MongoCollection<Document> collection = getCollection(collectionName);
try {
Bson filter = Filters.eq(MongoConfig.MONGO_ID, mongoObj.getDocument().getObjectId(MongoConfig.MONGO_ID));
mongoObj.setDocument(null);
Document document = objectToDocument(mongoObj);
UpdateResult result = collection.updateOne(filter, new Document(MongoConfig.$SET, document));
if (result.getMatchedCount() == 1) {
return true;
} else {
return false;
}
} catch (Exception e) {
if (log != null) {
log.error("修改记录失败", e);
}
return false;
}
}
ActivityConfigurationDaoBean.java 文件源码
项目:otus-api
阅读 42
收藏 0
点赞 0
评论 0
@Override
public ActivityCategory update(ActivityCategory activityCategory) throws DataNotFoundException {
BasicDBObject query = new BasicDBObject();
query.put("objectType", "ActivityCategory");
query.put("name", activityCategory.getName());
UpdateResult updateResult = collection.updateOne(query,
new Document("$set", new Document("label",activityCategory.getLabel())), new UpdateOptions().upsert(false));
if (updateResult.getMatchedCount() == 0){
throw new DataNotFoundException(
new Throwable("ActivityCategory {" + activityCategory.getName() + "} not found."));
}
return activityCategory;
}
ActivityConfigurationDaoBean.java 文件源码
项目:otus-api
阅读 32
收藏 0
点赞 0
评论 0
@Override
public void setNewDefault(String name) throws DataNotFoundException {
BasicDBObject query = new BasicDBObject();
query.put("objectType", "ActivityCategory");
query.put("isDefault", true);
UpdateResult undefaultResult = collection.updateOne(query, new Document("$set", new Document("isDefault", false)), new UpdateOptions().upsert(false));
if (undefaultResult.getMatchedCount() > 1){
throw new DataNotFoundException(
new Throwable("Default category error. More than one default found"));
}
BasicDBObject otherQuery = new BasicDBObject();
otherQuery.put("objectType", "ActivityCategory");
otherQuery.put("name", name);
UpdateResult defaultSetResult = collection.updateOne(otherQuery, new Document("$set", new Document("isDefault", true)), new UpdateOptions().upsert(false));
if (defaultSetResult.getMatchedCount() == 0){
throw new DataNotFoundException(
new Throwable("ActivityCategory {" + name + "} not found."));
}
}
ParticipantLaboratoryDaoBean.java 文件源码
项目:otus-api
阅读 24
收藏 0
点赞 0
评论 0
@Override
public Tube updateTubeCollectionData(long rn,Tube tube) throws DataNotFoundException {
Document parsedCollectionData = Document.parse(TubeCollectionData.serialize(tube.getTubeCollectionData()));
UpdateResult updateLabData = collection.updateOne(and(eq("recruitmentNumber", rn),
eq("tubes.code",tube.getCode())),
set("tubes.$.tubeCollectionData", parsedCollectionData),
new UpdateOptions().upsert(false));
if (updateLabData.getMatchedCount() == 0) {
throw new DataNotFoundException(new Throwable("Laboratory of Participant recruitment number: " + rn
+ " does not exists."));
}
return tube;
}
ProfiledMongoCollection.java 文件源码
项目:ibm-performance-monitor
阅读 34
收藏 0
点赞 0
评论 0
@Override
public UpdateResult updateMany(Bson filter, Bson arg1)
{
int writeSize = 0;
OperationMetric metric = null;
if (MongoLogger.GATHERER.isEnabled())
{
List<String> keyValuePairs = MongoUtilities.getKeyValuePairs(filter);
keyValuePairs.add("update");
keyValuePairs.add(arg1.toString());
String operationName = "Mongo : " + getNamespace().getCollectionName() + " : updateMany : " +
MongoUtilities.filterParameters(filter);
metric = startMetric(operationName, keyValuePairs);
addWriteConcern(metric);
}
UpdateResult retVal = collection.updateMany(filter, arg1);
insertUpdateResultProperties(metric, retVal);
stopMetric(metric, writeSize);
return retVal;
}
ProfiledMongoCollection.java 文件源码
项目:ibm-performance-monitor
阅读 28
收藏 0
点赞 0
评论 0
@Override
public UpdateResult updateMany(Bson filter, Bson arg1, UpdateOptions arg2)
{
int writeSize = 0;
OperationMetric metric = null;
if (MongoLogger.GATHERER.isEnabled())
{
List<String> keyValuePairs = MongoUtilities.getKeyValuePairs(filter);
keyValuePairs.add("update");
keyValuePairs.add(arg1.toString());
String operationName = "Mongo : " + getNamespace().getCollectionName() + " : updateMany : " +
MongoUtilities.filterParameters(filter);
metric = startMetric(operationName, keyValuePairs);
addWriteConcern(metric);
}
UpdateResult retVal = collection.updateMany(filter, arg1, arg2);
insertUpdateResultProperties(metric, retVal);
stopMetric(metric, writeSize);
return retVal;
}
ProfiledMongoCollection.java 文件源码
项目:ibm-performance-monitor
阅读 36
收藏 0
点赞 0
评论 0
@Override
public UpdateResult updateOne(Bson filter, Bson arg1)
{
int writeSize = 0;
OperationMetric metric = null;
if (MongoLogger.GATHERER.isEnabled())
{
List<String> keyValuePairs = MongoUtilities.getKeyValuePairs(filter);
keyValuePairs.add("update");
keyValuePairs.add(arg1.toString());
String operationName = "Mongo : " + getNamespace().getCollectionName() + " : updateOne : " +
MongoUtilities.filterParameters(filter);
metric = startMetric(operationName, keyValuePairs);
addWriteConcern(metric);
}
UpdateResult retVal = collection.updateOne(filter, arg1);
insertUpdateResultProperties(metric, retVal);
stopMetric(metric, writeSize);
return retVal;
}
ProfiledMongoCollection.java 文件源码
项目:ibm-performance-monitor
阅读 70
收藏 0
点赞 0
评论 0
@Override
public UpdateResult updateOne(Bson filter, Bson arg1, UpdateOptions arg2)
{
int writeSize = 0;
OperationMetric metric = null;
if (MongoLogger.GATHERER.isEnabled())
{
List<String> keyValuePairs = MongoUtilities.getKeyValuePairs(filter);
keyValuePairs.add("update");
keyValuePairs.add(arg1.toString());
String operationName = "Mongo : " + getNamespace().getCollectionName() + " : updateOne : " +
MongoUtilities.filterParameters(filter);
metric = startMetric(operationName, keyValuePairs);
addWriteConcern(metric);
}
UpdateResult retVal = collection.updateOne(filter, arg1, arg2);
insertUpdateResultProperties(metric, retVal);
stopMetric(metric, writeSize);
return retVal;
}
MongoDbRepository.java 文件源码
项目:hawkcd
阅读 26
收藏 0
点赞 0
评论 0
@Override
public T update(T entry) {
if (entry == null) {
return null;
}
try {
String entryToJson = this.jsonConverter.toJson(entry);
Document document = Document.parse(entryToJson);
UpdateResult updateResult = this.collection.replaceOne(eq("id", document.get("id")), document);
if (updateResult.getMatchedCount() == 1) { // means one record updated
return entry;
}
return null; //either none or many records updated, so consider the operation not successful.
} catch (RuntimeException e) {
LOGGER.error(e);
return null;
}
}
RefreshOperation.java 文件源码
项目:jpa-unit
阅读 26
收藏 0
点赞 0
评论 0
@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);
}
}
}
}
MongoDbProducer.java 文件源码
项目:Camel
阅读 29
收藏 0
点赞 0
评论 0
private Function<Exchange, Object> createDoSave() {
return exchange1 -> {
try {
MongoCollection<BasicDBObject> dbCol = calculateCollection(exchange1);
BasicDBObject saveObj = exchange1.getIn().getMandatoryBody(BasicDBObject.class);
UpdateOptions options = new UpdateOptions().upsert(true);
BasicDBObject queryObject = new BasicDBObject("_id", saveObj.get("_id"));
UpdateResult result = dbCol.replaceOne(queryObject, saveObj, options);
exchange1.getIn().setHeader(MongoDbConstants.OID, saveObj.get("_id"));
return result;
} catch (InvalidPayloadException e) {
throw new CamelMongoDbException("Body incorrect type for save", e);
}
};
}
MongoDbOperationsTest.java 文件源码
项目:Camel
阅读 29
收藏 0
点赞 0
评论 0
@Test
public void testSave() throws Exception {
// Prepare test
assertEquals(0, testCollection.count());
Object[] req = new Object[] {"{\"_id\":\"testSave1\", \"scientist\":\"Einstein\"}", "{\"_id\":\"testSave2\", \"scientist\":\"Copernicus\"}"};
Object result = template.requestBody("direct:insert", req);
assertTrue(result instanceof List);
assertEquals("Number of records persisted must be 2", 2, testCollection.count());
// Testing the save logic
DBObject record1 = testCollection.find(new BasicDBObject("_id", "testSave1")).first();
assertEquals("Scientist field of 'testSave1' must equal 'Einstein'", "Einstein", record1.get("scientist"));
record1.put("scientist", "Darwin");
result = template.requestBody("direct:save", record1);
assertTrue(result instanceof UpdateResult);
record1 = testCollection.find(new BasicDBObject("_id", "testSave1")).first();
assertEquals("Scientist field of 'testSave1' must equal 'Darwin' after save operation", "Darwin", record1.get("scientist"));
}
RenderDao.java 文件源码
项目:render
阅读 38
收藏 0
点赞 0
评论 0
public void updateZForSection(final StackId stackId,
final String sectionId,
final Double z)
throws IllegalArgumentException, IllegalStateException {
MongoUtil.validateRequiredParameter("stackId", stackId);
MongoUtil.validateRequiredParameter("sectionId", sectionId);
MongoUtil.validateRequiredParameter("z", z);
final MongoCollection<Document> tileCollection = getTileCollection(stackId);
final Document query = new Document("layout.sectionId", sectionId);
final Document update = new Document("$set", new Document("z", z));
final UpdateResult result = tileCollection.updateMany(query, update);
LOG.debug("updateZForSection: updated {} tile specs with {}.update({},{})",
result.getModifiedCount(), MongoUtil.fullName(tileCollection), query.toJson(), update.toJson());
}
RenderDao.java 文件源码
项目:render
阅读 29
收藏 0
点赞 0
评论 0
public void updateZForTiles(final StackId stackId,
final Double z,
final List<String> tileIds)
throws IllegalArgumentException, IllegalStateException {
MongoUtil.validateRequiredParameter("stackId", stackId);
MongoUtil.validateRequiredParameter("z", z);
MongoUtil.validateRequiredParameter("tileIds", tileIds);
final MongoCollection<Document> tileCollection = getTileCollection(stackId);
final Document query = new Document("tileId", new Document("$in", tileIds));
final Document update = new Document("$set", new Document("z", z));
final UpdateResult result = tileCollection.updateMany(query, update);
final String shortQueryForLog = "{ 'tileId': { '$in': [ " + tileIds.size() + " tile ids ... ] } }";
LOG.debug("updateZForTiles: updated {} tile specs with {}.update({},{})",
result.getModifiedCount(), MongoUtil.fullName(tileCollection), shortQueryForLog, update.toJson());
}
MongoBackendImpl.java 文件源码
项目:fiware-cygnus
阅读 36
收藏 0
点赞 0
评论 0
private void insertContextDataAggregatedForResoultion(String dbName, String collectionName,
GregorianCalendar calendar, String entityId, String entityType, String attrName, String attrType,
double max, double min, double sum, double sum2, int numSamples, Resolution resolution) {
// Get database and collection
MongoDatabase db = getDatabase(dbName);
MongoCollection collection = db.getCollection(collectionName);
// Build the query
BasicDBObject query = buildQueryForInsertAggregated(calendar, entityId, entityType, attrName, resolution);
// Prepopulate if needed
BasicDBObject insert = buildInsertForPrepopulate(attrType, resolution, true);
UpdateResult res = collection.updateOne(query, insert, new UpdateOptions().upsert(true));
if (res.getMatchedCount() == 0) {
LOGGER.debug("Prepopulating data, database=" + dbName + ", collection=" + collectionName + ", query="
+ query.toString() + ", insert=" + insert.toString());
} // if
// Do the update
BasicDBObject update = buildUpdateForUpdate(attrType, calendar, max, min, sum, sum2, numSamples);
LOGGER.debug("Updating data, database=" + dbName + ", collection=" + collectionName + ", query="
+ query.toString() + ", update=" + update.toString());
collection.updateOne(query, update);
}
EntityInvocationHandler.java 文件源码
项目:cherimodata
阅读 38
收藏 0
点赞 0
评论 0
/**
* stores the given EntityInvocationHandler represented Entity in the given Collection
*
* @param handler EntityInvocationHandler (Entity) to save
* @param coll MongoCollection to save entity into
*/
@SuppressWarnings( "unchecked" )
static <T extends Entity> void save( EntityInvocationHandler handler, MongoCollection<T> coll )
{
for ( ParameterProperty cpp : handler.properties.getValidationProperties() )
{
cpp.validate( handler.data.get( cpp.getMongoName() ) );
}
BsonDocumentWrapper wrapper = new BsonDocumentWrapper<>( handler.proxy,
(org.bson.codecs.Encoder<Entity>) coll.getCodecRegistry().get( handler.properties.getEntityClass() ) );
UpdateResult res = coll.updateOne(
new BsonDocument( "_id",
BsonDocumentWrapper.asBsonDocument( EntityCodec._obtainId( handler.proxy ), idRegistry ) ),
new BsonDocument( "$set", wrapper ), new UpdateOptions() );
if ( res.getMatchedCount() == 0 )
{
// TODO this seems too nasty, there must be a better way.for now live with it
coll.insertOne( (T) handler.proxy );
}
handler.persist();
}
Repositories.java 文件源码
项目:immutables
阅读 41
收藏 0
点赞 0
评论 0
protected final FluentFuture<Integer> doUpdate(
final Constraints.ConstraintHost criteria,
final Constraints.Constraint update,
final UpdateOptions options) {
checkNotNull(criteria, "criteria");
checkNotNull(update, "update");
checkNotNull(options, "options");
return submit(new Callable<UpdateResult>() {
@Override
public UpdateResult call() {
return collection()
.updateMany(
convertToBson(criteria),
convertToBson(update),
options);
}
}).lazyTransform(new Function<UpdateResult, Integer>() {
@Override
public Integer apply(UpdateResult input) {
return (int) input.getModifiedCount();
}
});
}
UpdateDocumentsImpl.java 文件源码
项目:mongodb-crud
阅读 40
收藏 0
点赞 0
评论 0
/**
* This method update only one one document which is matched first
*/
@Override
public void updateOneDocument() {
MongoDatabase db = null;
MongoCollection collection = null;
Bson filter = null;
Bson query = null;
try {
db = client.getDatabase(mongo.getDataBase());
collection = db.getCollection(mongo.getSampleCollection());
filter = eq("name", "Sundar");
query = combine(set("age", 23), set("gender", "Male"));
UpdateResult result = collection.updateOne(filter, query);
log.info("UpdateOne Status : " + result.wasAcknowledged());
log.info("No of Record Modified : " + result.getModifiedCount());
} catch (MongoException e) {
log.error("Exception occurred while update single Document : " + e, e);
}
}
MongoManager.java 文件源码
项目:rocketmq-flink-plugin
阅读 37
收藏 0
点赞 0
评论 0
/**
* @param dbName 库名
* @param collectionName 表名
* @param json1 条件
* @param json2 保存doc
* @return 更新结果信息
*/
public JSONObject executeUpdate(String dbName, String collectionName, JSONObject json1, JSONObject json2) {
JSONObject resp = new JSONObject();
try {
MongoDatabase db = mongoClient.getDatabase(dbName);
MongoCollection coll = db.getCollection(collectionName);
JSONObject saveJson = new JSONObject();
saveJson.put("$set", json2);
Document doc1 = Document.parse(json1.toString());
Document doc2 = Document.parse(saveJson.toString());
UpdateResult ur = coll.updateOne(doc1, doc2);
System.out.println("doc1 = " + doc1.toString());
System.out.println("doc2 = " + doc2.toString());
if (ur.isModifiedCountAvailable()) {
if (json1.containsKey(ID)) {
resp.put("Data", json1.get(ID));
} else {
resp.put("Data", json1);
}
}
} catch (MongoTimeoutException e1) {
e1.printStackTrace();
resp.put("ReasonMessage", e1.getClass() + ":" + e1.getMessage());
return resp;
} catch (Exception e) {
e.printStackTrace();
resp.put("ReasonMessage", e.getClass() + ":" + e.getMessage());
}
return resp;
}
MongoManager.java 文件源码
项目:rocketmq-flink-plugin
阅读 30
收藏 0
点赞 0
评论 0
/**
* @param dbName 库名
* @param collectionName 集合名
* @param json1 条件
* @param json2 保存doc
* @return upsert结果信息
*/
public JSONObject executeUpsert(String dbName, String collectionName, JSONObject json1, JSONObject json2) {
JSONObject resp = new JSONObject();
try {
MongoDatabase db = mongoClient.getDatabase(dbName);
MongoCollection coll = db.getCollection(collectionName);
JSONObject saveJson = new JSONObject();
saveJson.put("$set", json2);
Document doc1 = Document.parse(json1.toString());
Document doc2 = Document.parse(saveJson.toString());
UpdateOptions up = new UpdateOptions();
up.upsert(true);
UpdateResult ur = coll.updateOne(doc1, doc2, up);
if (ur.isModifiedCountAvailable()) {
if (json1.containsKey(ID)) {
resp.put("Data", json1.get(ID));
} else {
resp.put("Data", json1);
}
}
} catch (MongoTimeoutException e1) {
e1.printStackTrace();
resp.put("ReasonMessage", e1.getClass() + ":" + e1.getMessage());
return resp;
} catch (Exception e) {
e.printStackTrace();
resp.put("ReasonMessage", e.getClass() + ":" + e.getMessage());
}
return resp;
}
MongodbDataAccess.java 文件源码
项目:dooo
阅读 33
收藏 0
点赞 0
评论 0
/**
* 新增或者更新
*
* @param collectionName 集合名
* @param query 查询条件
* @param descData 目标数据
* @return
*/
public boolean upsert(String collectionName, MongodbQuery query, Map<String, Object> descData) {
MongoCollection collection = sMongoDatabase.getCollection(collectionName);
UpdateOptions options = new UpdateOptions();
options.upsert(true);
BasicDBObject updateSetValue = new BasicDBObject("$set", descData);
UpdateResult updateResult = collection.updateMany(query.getQuery(), updateSetValue, options);
return updateResult.getUpsertedId() != null ||
(updateResult.getMatchedCount() > 0 && updateResult.getModifiedCount() > 0);
}
NoteResource.java 文件源码
项目:Java-9-Programming-Blueprints
阅读 31
收藏 0
点赞 0
评论 0
@PUT
@Path("{id}")
public Response updateNote(Note note) {
note.setModified(LocalDateTime.now());
note.setUser(user.getId());
UpdateResult result =
collection.updateOne(buildQueryById(note.getId()),
new Document("$set", note.toDocument()));
if (result.getModifiedCount() == 0) {
return Response.status(Response.Status.NOT_FOUND).build();
} else {
return Response.ok().build();
}
}
UpdateOperation.java 文件源码
项目:mongodb-performance-test
阅读 26
收藏 0
点赞 0
评论 0
@Override
long executeQuery(int threadId, long threadRunCount, long globalRunCount, long selectorId, long randomId){
final Document doc = new Document("$set", new Document(RANDOM_LONG, randomId))
.append("$inc", new Document(VERSION, 1));
final UpdateResult res = THREAD_RUN_COUNT.equals(queriedField)?mongoCollection.updateMany(eq(queriedField, selectorId), doc)
:ID.equals(queriedField)?mongoCollection.updateOne(eq(queriedField, selectorId), doc):null;
return res!=null?res.getModifiedCount():0l;
}
ActivityDaoBean.java 文件源码
项目:otus-api
阅读 28
收藏 0
点赞 0
评论 0
@Override
public SurveyActivity update(SurveyActivity surveyActivity) throws DataNotFoundException {
Document parsed = Document.parse(SurveyActivity.serialize(surveyActivity));
parsed.remove("_id");
UpdateResult updateOne = collection.updateOne(eq("_id", surveyActivity.getActivityID()),
new Document("$set", parsed), new UpdateOptions().upsert(false));
if (updateOne.getMatchedCount() == 0) {
throw new DataNotFoundException(
new Throwable("OID {" + surveyActivity.getActivityID().toString() + "} not found."));
}
return surveyActivity;
}
ActivityDaoBean.java 文件源码
项目:otus-api
阅读 34
收藏 0
点赞 0
评论 0
@Override
public void updateCategory(ActivityCategory activityCategory){
Document query = new Document();
query.put("category.name", activityCategory.getName());
UpdateResult updateResult = collection.updateOne(query, new Document("$set", new Document("category.label", activityCategory.getLabel())), new UpdateOptions().upsert(false));
}
ActivityConfigurationDaoBean.java 文件源码
项目:otus-api
阅读 28
收藏 0
点赞 0
评论 0
@Override
public void disable(String name) throws DataNotFoundException {
BasicDBObject query = new BasicDBObject();
query.put("objectType", "ActivityCategory");
query.put("name", name);
UpdateResult updateResult = collection.updateOne(query, new Document("$set", new Document("disabled", true)), new UpdateOptions().upsert(false));
if (updateResult.getMatchedCount() == 0) {
throw new DataNotFoundException(
new Throwable("ActivityCategory {" + name + "} not found.")); }
}
ExamLotDaoBean.java 文件源码
项目:otus-api
阅读 23
收藏 0
点赞 0
评论 0
@Override
public ExamLot update(ExamLot examLot) throws DataNotFoundException {
Document parsed = Document.parse(ExamLot.serialize(examLot));
parsed.remove("_id");
UpdateResult updateLotData = collection.updateOne(eq("code", examLot.getCode()), new Document("$set", parsed),
new UpdateOptions().upsert(false));
if (updateLotData.getMatchedCount() == 0) {
throw new DataNotFoundException(new Throwable("Exam Lot not found"));
}
return examLot;
}