use of com.mongodb.client.model.InsertManyOptions in project storm by apache.
the class MongoDBClient method insert.
/**
* Inserts one or more documents.
* This method is equivalent to a call to the bulkWrite method.
* The documents will be inserted in the order provided,
* stopping on the first failed insertion.
*
* @param documents
*/
public void insert(List<Document> documents, boolean ordered) {
InsertManyOptions options = new InsertManyOptions();
if (!ordered) {
options.ordered(false);
}
collection.insertMany(documents, options);
}
use of com.mongodb.client.model.InsertManyOptions in project zeppelin by apache.
the class MongoNotebookRepo method insertFileSystemNotes.
/**
* 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 {
// docs to be imported
LinkedList<Document> docs = new LinkedList<>();
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) {
//print duplicated document warning log
printDuplicatedException(e);
}
// it does nothing for now but maybe in the future...
vfsRepo.close();
}
use of com.mongodb.client.model.InsertManyOptions in project presto by prestodb.
the class MongoPageSink method appendPage.
@Override
public CompletableFuture<?> appendPage(Page page) {
MongoCollection<Document> collection = mongoSession.getCollection(schemaTableName);
List<Document> batch = new ArrayList<>(page.getPositionCount());
for (int position = 0; position < page.getPositionCount(); position++) {
Document doc = new Document();
for (int channel = 0; channel < page.getChannelCount(); channel++) {
MongoColumnHandle column = columns.get(channel);
doc.append(column.getName(), getObjectValue(columns.get(channel).getType(), page.getBlock(channel), position));
}
batch.add(doc);
}
collection.insertMany(batch, new InsertManyOptions().ordered(true));
return NOT_BLOCKED;
}
use of com.mongodb.client.model.InsertManyOptions in project mongo-java-driver by mongodb.
the class JsonPoweredCrudTestHelper method getInsertManyResult.
BsonDocument getInsertManyResult(final BsonDocument arguments) {
List<BsonDocument> documents = new ArrayList<BsonDocument>();
for (BsonValue document : arguments.getArray("documents")) {
documents.add(document.asDocument());
}
collection.insertMany(documents, new InsertManyOptions().ordered(arguments.getBoolean("ordered", BsonBoolean.TRUE).getValue()));
BsonArray insertedIds = new BsonArray();
for (BsonDocument document : documents) {
insertedIds.add(document.get("_id"));
}
return toResult(new BsonDocument("insertedIds", insertedIds));
}
Aggregations