use of org.bson.BsonDocumentWrapper in project mongo-java-driver by mongodb.
the class ClusterFixture method enableMaxTimeFailPoint.
public static void enableMaxTimeFailPoint() {
assumeThat(isSharded(), is(false));
new CommandWriteOperation<BsonDocument>("admin", new BsonDocumentWrapper<Document>(new Document("configureFailPoint", "maxTimeAlwaysTimeOut").append("mode", "alwaysOn"), new DocumentCodec()), new BsonDocumentCodec()).execute(getBinding());
}
use of org.bson.BsonDocumentWrapper in project mongo-java-driver by mongodb.
the class DBCollection method insert.
/**
* <p>Insert documents into a collection. If the collection does not exists on the server, then it will be created. If the new document
* does not contain an '_id' field, it will be added.</p>
*
* <p>If the value of the continueOnError property of the given {@code InsertOptions} is true,
* that value will override the value of the continueOnError property of the given {@code WriteConcern}. Otherwise,
* the value of the continueOnError property of the given {@code WriteConcern} will take effect. </p>
*
* @param documents a list of {@code DBObject}'s to be inserted
* @param insertOptions the options to use for the insert
* @return the result of the operation
* @throws com.mongodb.DuplicateKeyException if the write failed to a duplicate unique key
* @throws com.mongodb.WriteConcernException if the write failed due some other failure specific to the insert command
* @throws MongoException if the operation failed for some other reason
* @mongodb.driver.manual tutorial/insert-documents/ Insert Documents
*/
public WriteResult insert(final List<? extends DBObject> documents, final InsertOptions insertOptions) {
WriteConcern writeConcern = insertOptions.getWriteConcern() != null ? insertOptions.getWriteConcern() : getWriteConcern();
Encoder<DBObject> encoder = toEncoder(insertOptions.getDbEncoder());
List<InsertRequest> insertRequestList = new ArrayList<InsertRequest>(documents.size());
for (DBObject cur : documents) {
if (cur.get(ID_FIELD_NAME) == null) {
cur.put(ID_FIELD_NAME, new ObjectId());
}
insertRequestList.add(new InsertRequest(new BsonDocumentWrapper<DBObject>(cur, encoder)));
}
return insert(insertRequestList, writeConcern, insertOptions.isContinueOnError(), insertOptions.getBypassDocumentValidation());
}
Aggregations