@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); }
/** * * @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); } }
@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); } }
/** * 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... }
@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); } } }
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; } }); }
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; } }); }
@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); }
@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)); } })); }
@Override public Publisher<Success> insertMany(final ClientSession clientSession, 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(clientSession, documents, options, voidToSuccessCallback(callback)); } })); }
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; }
@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()); }
@Override public void insertMany(final List<Document> items) { collection.insertMany(items, new InsertManyOptions().ordered(false)); }
@Override public Observable<Success> insertMany(final List<? extends TDocument> documents) { return insertMany(documents, new InsertManyOptions()); }
@Override public Publisher<Success> insertMany(final List<? extends TDocument> documents) { return insertMany(documents, new InsertManyOptions()); }
@Override public Publisher<Success> insertMany(final ClientSession clientSession, final List<? extends TDocument> documents) { return insertMany(clientSession, documents, new InsertManyOptions()); }
/** * * @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); }
/** * Inserts a batch of documents. The preferred way to perform bulk inserts is to use the BulkWrite API. However, when talking with a * server < 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);
/** * Inserts a batch of documents. The preferred way to perform bulk inserts is to use the BulkWrite API. However, when talking with a * server < 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);
/** * Inserts a batch of documents. The preferred way to perform bulk inserts is to use the BulkWrite API. However, when talking with a * server < 2.6, using this method will be faster due to constraints in the bulk API related to error handling. * * @param clientSession the client session with which to associate this operation * @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 * @mongodb.server.release 3.6 * @since 1.7 */ Publisher<Success> insertMany(ClientSession clientSession, List<? extends TDocument> documents, InsertManyOptions options);