本文整理汇总了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);
}
示例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);
}
}
示例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);
}
}
示例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...
}
示例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);
}
}
}
示例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;
}
});
}
示例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;
}
});
}
示例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);
}
示例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));
}
}));
}
示例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;
}
示例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());
}
示例12: insertMany
import com.mongodb.client.model.InsertManyOptions; //导入依赖的package包/类
@Override
public void insertMany(final List<Document> items) {
collection.insertMany(items, new InsertManyOptions().ordered(false));
}
示例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);
}
示例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 < 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);
示例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 < 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);