当前位置: 首页>>代码示例>>Java>>正文


Java MongoClient.updateCollection方法代码示例

本文整理汇总了Java中io.vertx.ext.mongo.MongoClient.updateCollection方法的典型用法代码示例。如果您正苦于以下问题:Java MongoClient.updateCollection方法的具体用法?Java MongoClient.updateCollection怎么用?Java MongoClient.updateCollection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.vertx.ext.mongo.MongoClient的用法示例。


在下文中一共展示了MongoClient.updateCollection方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateRepoWithLogging

import io.vertx.ext.mongo.MongoClient; //导入方法依赖的package包/类
/**
 * Helper class to update mongodb status
 * @param mongo
 * @param COLLECTION
 * @param updateJob
 * @param LOG
 */
public static void updateRepoWithLogging(MongoClient mongo, String COLLECTION, DFJobPOPJ updateJob, Logger LOG) {
    mongo.updateCollection(COLLECTION, new JsonObject().put("_id", updateJob.getId()),
            // The update syntax: {$set, the json object containing the fields to update}
            new JsonObject().put("$set", updateJob.toJson()), v -> {
                if (v.failed()) {
                    LOG.error(DFAPIMessage.logResponseMessage(9003, updateJob.getId() + "cause:" + v.cause()));
                } else {
                    LOG.info(DFAPIMessage.logResponseMessage(1021, updateJob.getId()));
                }
            }
    );
}
 
开发者ID:datafibers-community,项目名称:df_data_service,代码行数:20,代码来源:HelpFunc.java

示例2: example5

import io.vertx.ext.mongo.MongoClient; //导入方法依赖的package包/类
public void example5(MongoClient mongoClient) {
  // Match any documents with title=The Hobbit
  JsonObject query = new JsonObject()
    .put("title", "The Hobbit");
  // Set the author field
  JsonObject update = new JsonObject().put("$set", new JsonObject()
    .put("author", "J. R. R. Tolkien"));
  mongoClient.updateCollection("books", query, update, res -> {
    if (res.succeeded()) {
      System.out.println("Book updated !");
    } else {
      res.cause().printStackTrace();
    }
  });
}
 
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:16,代码来源:Examples.java

示例3: forwardPUTAsUpdateOne

import io.vertx.ext.mongo.MongoClient; //导入方法依赖的package包/类
/**
 * This method first decode the REST PUT request to DFJobPOPJ object.
 * Then, it updates its job status immediately in the repository and response to ui
 * After that, it repacks the request for Kafka REST PUT and forward the new POST to Kafka Connect.
 *
 * @param routingContext This is the connect from REST API
 * @param webClient This is vertx non-blocking rest client used for forwarding
 * @param mongoClient This is the client used to insert final data to repository - mongodb
 * @param mongoCOLLECTION This is mongodb collection name
 * @param kafkaConnectRestHost rest server host name
 * @param kafkaConnectRestPort rest server port number
 * @param dfJobResponsed This is the response object return to rest client or ui or mongo insert
 */
public static void forwardPUTAsUpdateOne (RoutingContext routingContext, WebClient webClient,
                                          MongoClient mongoClient, String mongoCOLLECTION,
                                          String kafkaConnectRestHost, int kafkaConnectRestPort,
                                          DFJobPOPJ dfJobResponsed) {

    final String id = routingContext.request().getParam("id");
    final String restURL = ConstantApp.KAFKA_CONNECT_PLUGIN_CONFIG.
            replace("CONNECTOR_NAME_PLACEHOLDER", dfJobResponsed.getConnectUid());

    webClient.put(kafkaConnectRestPort, kafkaConnectRestHost, restURL)
            .putHeader(ConstantApp.HTTP_HEADER_CONTENT_TYPE, ConstantApp.HTTP_HEADER_APPLICATION_JSON_CHARSET)
            .sendJsonObject(dfJobResponsed.toKafkaConnectJsonConfig(),
                    ar -> {
                        if (ar.succeeded()) {
                            LOG.info(DFAPIMessage.logResponseMessage(1000, dfJobResponsed.getId()));
                        } else {
                            // If response is failed, repose df ui and still keep the task
                            HelpFunc.responseCorsHandleAddOn(routingContext.response())
                                    .setStatusCode(ConstantApp.STATUS_CODE_BAD_REQUEST)
                                    .end(DFAPIMessage.getResponseMessage(9038));
                            LOG.info(DFAPIMessage.logResponseMessage(9038, dfJobResponsed.getId()));
                        }
                    }
            );
    // Here update the repo right way to ack ui. Even something is wrong, status sync. can still catch the update
    mongoClient.updateCollection(mongoCOLLECTION, new JsonObject().put("_id", id),
            // The update syntax: {$set, the json object containing the fields to update}
            new JsonObject().put("$set", dfJobResponsed.toJson()), v -> {
                if (v.failed()) {
                    routingContext.response()
                            .setStatusCode(ConstantApp.STATUS_CODE_NOT_FOUND)
                            .end(DFAPIMessage.getResponseMessage(9003));
                    LOG.error(DFAPIMessage.logResponseMessage(9003, id));
                } else {
                    HelpFunc.responseCorsHandleAddOn(routingContext.response())
                            .end(DFAPIMessage.getResponseMessage(1000));
                    LOG.info(DFAPIMessage.logResponseMessage(1000, id));
                }
            });
}
 
开发者ID:datafibers-community,项目名称:df_data_service,代码行数:54,代码来源:ProcessorConnectKafka.java


注:本文中的io.vertx.ext.mongo.MongoClient.updateCollection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。