use of com.mongodb.client.ClientSession in project morphia by mongodb.
the class PipelineUpdate method execute.
/**
* Executes the update
*
* @param options the options to apply
* @return the results
*/
public UpdateResult execute(UpdateOptions options) {
List<Document> updateOperations = toDocument();
final Document queryObject = query.toDocument();
ClientSession session = datastore.findSession(options);
MongoCollection<T> mongoCollection = options.prepare(collection);
if (options.isMulti()) {
return session == null ? mongoCollection.updateMany(queryObject, updateOperations, options) : mongoCollection.updateMany(session, queryObject, updateOperations, options);
} else {
return session == null ? mongoCollection.updateOne(queryObject, updateOperations, options) : mongoCollection.updateOne(session, queryObject, updateOperations, options);
}
}
use of com.mongodb.client.ClientSession in project drill by apache.
the class MongoModify method executeOperations.
private void executeOperations(List<MongoOperation> operations) {
ClientSession clientSession = context.client().startSession();
String res = clientSession.withTransaction(() -> {
operations.forEach(o -> o.execute(context.table()));
return String.format("executed %s operations", operations.size());
});
logger.debug(res);
}
Aggregations