• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java InsertManyOptions类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.mongodb.client.model.InsertManyOptions的典型用法代码示例。如果您正苦于以下问题:Java InsertManyOptions类的具体用法?Java InsertManyOptions怎么用?Java InsertManyOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



InsertManyOptions类属于com.mongodb.client.model包,在下文中一共展示了InsertManyOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: insertMany

import com.mongodb.client.model.InsertManyOptions; //导入依赖的package包/类
@Override
public void insertMany(List<? extends TDocument> arg0, InsertManyOptions arg1)
{
    int writeSize = 0;
    OperationMetric metric = null;
    if (MongoLogger.GATHERER.isEnabled())
    {
        List<String> keyValuePairs = createWriteKeyValuePairs();
        String operationName = "Mongo : " + getNamespace().getCollectionName() + " : insertMany";
        metric = startMetric(operationName, keyValuePairs);
        metric.setProperty(CommonMetricProperties.REQUEST_OBJECT_COUNT, Integer.toString(arg0.size()));
        addWriteConcern(metric);

        if (MongoLogger.isRequestSizeMeasured())
        {
            writeSize = arg0.toString().length();
            metric.setProperty(CommonMetricProperties.REQUEST_SIZE_BYTES, Integer.toString(writeSize));
        }
    }

    collection.insertMany(arg0, arg1);

    stopMetric(metric, writeSize);
}
 
开发者ID:dd00f,项目名称:ibm-performance-monitor,代码行数:25,代码来源:ProfiledMongoCollection.java


示例2: insert

import com.mongodb.client.model.InsertManyOptions; //导入依赖的package包/类
/**
 *
 * @param objList list of <code>Document/Map<String, Object>/entity</code> class with getter/setter method.
 * @param options
 */
public void insert(final Collection<?> objList, final InsertManyOptions options) {
    List<Document> docs = null;

    if (objList.iterator().next() instanceof Document) {
        if (objList instanceof List) {
            docs = (List<Document>) objList;
        } else {
            docs = new ArrayList<>((Collection<Document>) objList);
        }
    } else {
        docs = new ArrayList<>(objList.size());

        for (Object entity : objList) {
            docs.add(createDocument(entity));
        }
    }

    if (options == null) {
        coll.insertMany(docs);
    } else {
        coll.insertMany(docs, options);
    }
}
 
开发者ID:landawn,项目名称:AbacusUtil,代码行数:29,代码来源:MongoCollectionExecutor.java


示例3: bulkInsert

import com.mongodb.client.model.InsertManyOptions; //导入依赖的package包/类
@Override
public void bulkInsert(List<T> entities) {
    if (entities == null || entities.isEmpty()) throw Exceptions.error("entities must not be empty");

    StopWatch watch = new StopWatch();
    for (T entity : entities) {
        validator.validate(entity);
    }
    try {
        collection().insertMany(entities, new InsertManyOptions().ordered(false));
    } finally {
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("mongoDB", elapsedTime, 0, entities.size());
        logger.debug("bulkInsert, collection={}, size={}, elapsedTime={}", collectionName, entities.size(), elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
 
开发者ID:neowu,项目名称:core-ng-project,代码行数:18,代码来源:MongoCollectionImpl.java


示例4: insertFileSystemNotes

import com.mongodb.client.model.InsertManyOptions; //导入依赖的package包/类
/**
 * If environment variable ZEPPELIN_NOTEBOOK_MONGO_AUTOIMPORT is true,
 * this method will insert local notes into MongoDB on startup.
 * If a note already exists in MongoDB, skip it.
 */
private void insertFileSystemNotes() throws IOException {
  LinkedList<Document> docs = new LinkedList<>(); // docs to be imported
  NotebookRepo vfsRepo = new VFSNotebookRepo(this.conf);
  List<NoteInfo> infos =  vfsRepo.list(null);
  // collect notes to be imported
  for (NoteInfo info : infos) {
    Note note = vfsRepo.get(info.getId(), null);
    Document doc = noteToDocument(note);
    docs.add(doc);
  }

  /*
   * 'ordered(false)' option allows to proceed bulk inserting even though
   * there are duplicated documents. The duplicated documents will be skipped
   * and print a WARN log.
   */
  try {
    coll.insertMany(docs, new InsertManyOptions().ordered(false));
  } catch (MongoBulkWriteException e) {
    printDuplicatedException(e);  //print duplicated document warning log
  }

  vfsRepo.close();  // it does nothing for now but maybe in the future...
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:30,代码来源:MongoNotebookRepo.java


示例5: asyncInsert

import com.mongodb.client.model.InsertManyOptions; //导入依赖的package包/类
@Override
public void asyncInsert(
    String database,
    String collection,
    boolean continueOnError,
    List<? extends BsonDocument> docsToInsert) throws MongoException {
  try {
    owner.getDriverClient()
        .getDatabase(database)
        .getCollection(collection, BsonDocument.class)
        .insertMany(docsToInsert, new InsertManyOptions()
            .ordered(continueOnError));
  } catch (com.mongodb.MongoException ex) { //a general Mongo driver exception
    if (ErrorCode.isErrorCode(ex.getCode())) {
      throw toMongoException(ex);
    } else {
      throw toRuntimeMongoException(ex);
    }
  }
}
 
开发者ID:torodb,项目名称:mongowp,代码行数:21,代码来源:MongoConnectionWrapper.java


示例6: insert

import com.mongodb.client.model.InsertManyOptions; //导入依赖的package包/类
public CompletableFuture<Void> insert(final String collectionName, final Collection<?> objList, final InsertManyOptions options) {
    return asyncExecutor.execute(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            dbExecutor.insert(collectionName, objList, options);
            return null;
        }
    });
}
 
开发者ID:landawn,项目名称:AbacusUtil,代码行数:10,代码来源:AsyncMongoDBExecutor.java


示例7: insert

import com.mongodb.client.model.InsertManyOptions; //导入依赖的package包/类
public CompletableFuture<Void> insert(final Collection<?> objList, final InsertManyOptions options) {
    return asyncExecutor.execute(new Callable<Void>() {
        @Override
        public Void call() throws Exception {
            collExecutor.insert(objList, options);
            return null;
        }
    });
}
 
开发者ID:landawn,项目名称:AbacusUtil,代码行数:10,代码来源:AsyncMongoCollectionExecutor.java


示例8: insertMany

import com.mongodb.client.model.InsertManyOptions; //导入依赖的package包/类
@Override
public Observable<Success> insertMany(final List<? extends TDocument> documents, final InsertManyOptions options) {
    return RxObservables.create(Observables.observe(new Block<SingleResultCallback<Success>>() {
        @Override
        public void apply(final SingleResultCallback<Success> callback) {
            wrapped.insertMany(documents, options, voidToSuccessCallback(callback));
        }
    }), observableAdapter);
}
 
开发者ID:mongodb,项目名称:mongo-java-driver-rx,代码行数:10,代码来源:MongoCollectionImpl.java


示例9: insertMany

import com.mongodb.client.model.InsertManyOptions; //导入依赖的package包/类
@Override
public Publisher<Success> insertMany(final List<? extends TDocument> documents, final InsertManyOptions options) {
    return new ObservableToPublisher<Success>(observe(new Block<SingleResultCallback<Success>>() {
        @Override
        public void apply(final SingleResultCallback<Success> callback) {
            wrapped.insertMany(documents, options, voidToSuccessCallback(callback));
        }
    }));
}
 
开发者ID:mongodb,项目名称:mongo-java-driver-reactivestreams,代码行数:10,代码来源:MongoCollectionImpl.java


示例10: capture

import com.mongodb.client.model.InsertManyOptions; //导入依赖的package包/类
public HashMap<String, Object> capture(List<BsonDocument> bsonDocumentList) {
	HashMap<String, Object> retMsg = new HashMap<String, Object>();
	MongoCollection<BsonDocument> collection = Configuration.mongoDatabase.getCollection("EventData",
			BsonDocument.class);
	try {
		InsertManyOptions option = new InsertManyOptions();
		option.ordered(false);
		collection.insertMany(bsonDocumentList, option);
	} catch (MongoBulkWriteException e) {
		retMsg.put("error", e.getMessage());
		return retMsg;
	}
	retMsg.put("eventCaptured", bsonDocumentList.size());
	return retMsg;
}
 
开发者ID:JaewookByun,项目名称:epcis,代码行数:16,代码来源:MongoCaptureUtil.java


示例11: setup

import com.mongodb.client.model.InsertManyOptions; //导入依赖的package包/类
@BeforeClass
    public static void setup()
    {
        String mongoUrl = "mongodb://localhost:27017";

        try
        {
            Properties prop = new Properties();
            prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("mongo.properties"));
            mongoUrl = prop.getProperty("mongourl");
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }

        // create an instance of client and establish the connection
        MongoClientURI connectionString = new MongoClientURI(mongoUrl);
        m1 = new MongoClient(connectionString);
        client = new ProfiledMongoClient(m1);

        db = client.getDatabase("testMongo");

        coll = db.getCollection("car");

        coll.insertOne(Document.parse(
            "{\"car_id\":\"c1\",\"name\":\"Audi\",\"color\":\"Black\",\"cno\":\"H110\",\"mfdcountry\":\"Germany\",\"speed\":72,\"price\":11.25}"));
        coll.insertOne(Document.parse(
            "{\"car_id\":\"c2\",\"name\":\"Polo\",\"color\":\"White\",\"cno\":\"H111\",\"mfdcountry\":\"Japan\",\"speed\":65,\"price\":8.5}"));
        coll.insertOne(Document.parse(
            "{\"car_id\":\"c3\",\"name\":\"Alto\",\"color\":\"Silver\",\"cno\":\"H112\",\"mfdcountry\":\"India\",\"speed\":53,\"price\":4.5}"));
        coll.insertOne(
            Document.parse(
                "{\"car_id\":\"c4\",\"name\":\"Santro\",\"color\":\"Grey\",\"cno\":\"H113\",\"mfdcountry\":\"Sweden\",\"speed\":89,\"price\":3.5}"),
            new InsertOneOptions());

        gatherer = (TestLogMetricGatherer) MongoLogger.GATHERER;

//        assertEquals("Mongo : car : insertOne", gatherer.getLastMetric().getOperationName());
//        assertEquals("car", gatherer.getLastMetric().getProperty(MongoProperties.MONGO_COLLECTION));
//        assertEquals("testMongo", gatherer.getLastMetric().getProperty(MongoProperties.MONGO_DATABASE));

        coll.insertMany(Arrays.asList(
            Document.parse(
                "{\"car_id\":\"c5\",\"name\":\"Zen\",\"color\":\"Blue\",\"cno\":\"H114\",\"mfdcountry\":\"Denmark\",\"speed\":94,\"price\":6.5}"),
            Document.parse(
                "{\"car_id\":\"c6\",\"name\":\"Alto\",\"color\":\"Blue\",\"cno\":\"H115\",\"mfdcountry\":\"India\",\"speed\":53,\"price\":4.5}")));

        coll.insertMany(
            Arrays.asList(
                Document.parse(
                    "{\"car_id\":\"c6\",\"name\":\"Alto\",\"color\":\"White\",\"cno\":\"H115\",\"mfdcountry\":\"India\",\"speed\":53,\"price\":4.5}"),
                Document.parse(
                    "{\"car_id\":\"c6\",\"name\":\"Alto\",\"color\":\"Red\",\"cno\":\"H115\",\"mfdcountry\":\"India\",\"speed\":53,\"price\":4.5}")),
            new InsertManyOptions());

    }
 
开发者ID:dd00f,项目名称:ibm-performance-monitor,代码行数:58,代码来源:ProfiledMongoClientTest.java


示例12: insertMany

import com.mongodb.client.model.InsertManyOptions; //导入依赖的package包/类
@Override
public void insertMany(final List<Document> items) {
    collection.insertMany(items, new InsertManyOptions().ordered(false));
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:5,代码来源:MongoCollectionType.java


示例13: insert

import com.mongodb.client.model.InsertManyOptions; //导入依赖的package包/类
/**
 *
 * @param collectionName
 * @param objList list of <code>Document/Map<String, Object>/entity</code> class with getter/setter method.
 * @param options
 */
public void insert(final String collectionName, final Collection<?> objList, final InsertManyOptions options) {
    collExecutor(collectionName).insert(objList, options);
}
 
开发者ID:landawn,项目名称:AbacusUtil,代码行数:10,代码来源:MongoDBExecutor.java


示例14: insertMany

import com.mongodb.client.model.InsertManyOptions; //导入依赖的package包/类
/**
 * Inserts a batch of documents. The preferred way to perform bulk inserts is to use the BulkWrite API. However, when talking with a
 * server &lt; 2.6, using this method will be faster due to constraints in the bulk API related to error handling.
 *
 * @param documents the documents to insert
 * @param options   the options to apply to the operation
 * @return an Observable with a single element indicating when the operation has completed or with either a
 * com.mongodb.DuplicateKeyException or com.mongodb.MongoException
 */
Observable<Success> insertMany(List<? extends TDocument> documents, InsertManyOptions options);
 
开发者ID:mongodb,项目名称:mongo-java-driver-rx,代码行数:11,代码来源:MongoCollection.java


示例15: insertMany

import com.mongodb.client.model.InsertManyOptions; //导入依赖的package包/类
/**
 * Inserts a batch of documents. The preferred way to perform bulk inserts is to use the BulkWrite API. However, when talking with a
 * server &lt; 2.6, using this method will be faster due to constraints in the bulk API related to error handling.
 *
 * @param documents the documents to insert
 * @param options   the options to apply to the operation
 * @return a publisher with a single element indicating when the operation has completed or with either a
 * com.mongodb.DuplicateKeyException or com.mongodb.MongoException
 */
Publisher<Success> insertMany(List<? extends TDocument> documents, InsertManyOptions options);
 
开发者ID:mongodb,项目名称:mongo-java-driver-reactivestreams,代码行数:11,代码来源:MongoCollection.java



注:本文中的com.mongodb.client.model.InsertManyOptions类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java YamlPropertySourceLoader类代码示例发布时间:2022-05-22
下一篇:
Java LocalStrategy类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap