Search in sources :

Example 6 with InsertRequest

use of com.mongodb.bulk.InsertRequest in project mongo-java-driver by mongodb.

the class MongoCollectionImpl method insertOne.

@Override
public void insertOne(final TDocument document, final InsertOneOptions options, final SingleResultCallback<Void> callback) {
    TDocument insertDocument = document;
    if (getCodec() instanceof CollectibleCodec) {
        insertDocument = ((CollectibleCodec<TDocument>) getCodec()).generateIdIfAbsentFromDocument(insertDocument);
    }
    executeSingleWriteRequest(new InsertRequest(documentToBsonDocument(insertDocument)), options.getBypassDocumentValidation(), new SingleResultCallback<BulkWriteResult>() {

        @Override
        public void onResult(final BulkWriteResult result, final Throwable t) {
            callback.onResult(null, t);
        }
    });
}
Also used : CollectibleCodec(org.bson.codecs.CollectibleCodec) InsertRequest(com.mongodb.bulk.InsertRequest) BulkWriteResult(com.mongodb.bulk.BulkWriteResult)

Example 7 with InsertRequest

use of com.mongodb.bulk.InsertRequest in project mongo-java-driver by mongodb.

the class MongoCollectionImpl method insertOne.

@Override
public void insertOne(final TDocument document, final InsertOneOptions options) {
    notNull("document", document);
    TDocument insertDocument = document;
    if (getCodec() instanceof CollectibleCodec) {
        insertDocument = ((CollectibleCodec<TDocument>) getCodec()).generateIdIfAbsentFromDocument(document);
    }
    executeSingleWriteRequest(new InsertRequest(documentToBsonDocument(insertDocument)), options.getBypassDocumentValidation());
}
Also used : CollectibleCodec(org.bson.codecs.CollectibleCodec) InsertRequest(com.mongodb.bulk.InsertRequest)

Example 8 with InsertRequest

use of com.mongodb.bulk.InsertRequest in project mongo-java-driver by mongodb.

the class MaxDocumentSizeTest method setUp.

@Before
public void setUp() {
    message = new InsertMessage("test.test", true, ACKNOWLEDGED, asList(new InsertRequest(new BsonDocument("bytes", new BsonBinary(new byte[2048])))), MessageSettings.builder().maxDocumentSize(1024).build());
    buffer = new ByteBufferBsonOutput(new SimpleBufferProvider());
}
Also used : BsonDocument(org.bson.BsonDocument) BsonBinary(org.bson.BsonBinary) InsertRequest(com.mongodb.bulk.InsertRequest) Before(org.junit.Before)

Example 9 with InsertRequest

use of com.mongodb.bulk.InsertRequest in project mongo-java-driver by mongodb.

the class MaxMessageSizeTest method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() {
    BsonBinary binary = new BsonBinary(new byte[2048]);
    message = new InsertMessage("test.test", true, ACKNOWLEDGED, Arrays.asList(new InsertRequest(new BsonDocument("bytes", binary)), new InsertRequest(new BsonDocument("bytes", binary)), new InsertRequest(new BsonDocument("bytes", binary))), MessageSettings.builder().maxMessageSize(4500).build());
    buffer = new ByteBufferBsonOutput(new SimpleBufferProvider());
}
Also used : BsonDocument(org.bson.BsonDocument) BsonBinary(org.bson.BsonBinary) InsertRequest(com.mongodb.bulk.InsertRequest) Before(org.junit.Before)

Aggregations

InsertRequest (com.mongodb.bulk.InsertRequest)9 CollectibleCodec (org.bson.codecs.CollectibleCodec)6 ArrayList (java.util.ArrayList)5 MixedBulkWriteOperation (com.mongodb.operation.MixedBulkWriteOperation)4 BulkWriteResult (com.mongodb.bulk.BulkWriteResult)2 DeleteRequest (com.mongodb.bulk.DeleteRequest)2 UpdateRequest (com.mongodb.bulk.UpdateRequest)2 WriteRequest (com.mongodb.bulk.WriteRequest)2 DeleteManyModel (com.mongodb.client.model.DeleteManyModel)2 DeleteOneModel (com.mongodb.client.model.DeleteOneModel)2 InsertOneModel (com.mongodb.client.model.InsertOneModel)2 ReplaceOneModel (com.mongodb.client.model.ReplaceOneModel)2 UpdateManyModel (com.mongodb.client.model.UpdateManyModel)2 UpdateOneModel (com.mongodb.client.model.UpdateOneModel)2 BsonBinary (org.bson.BsonBinary)2 BsonDocument (org.bson.BsonDocument)2 Before (org.junit.Before)2 SingleResultCallback (com.mongodb.async.SingleResultCallback)1 BsonDocumentWrapper (org.bson.BsonDocumentWrapper)1 ObjectId (org.bson.types.ObjectId)1