Search in sources :

Example 6 with DeleteRequest

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

the class OperationHelper method validateWriteRequestCollations.

static void validateWriteRequestCollations(final Connection connection, final List<? extends WriteRequest> requests, final WriteConcern writeConcern) {
    Collation collation = null;
    for (WriteRequest request : requests) {
        if (request instanceof UpdateRequest) {
            collation = ((UpdateRequest) request).getCollation();
        } else if (request instanceof DeleteRequest) {
            collation = ((DeleteRequest) request).getCollation();
        }
        if (collation != null) {
            break;
        }
    }
    validateCollationAndWriteConcern(connection, collation, writeConcern);
}
Also used : UpdateRequest(com.mongodb.bulk.UpdateRequest) WriteRequest(com.mongodb.bulk.WriteRequest) Collation(com.mongodb.client.model.Collation) DeleteRequest(com.mongodb.bulk.DeleteRequest)

Example 7 with DeleteRequest

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

the class DeleteCommandMessage method writeTheWrites.

@Override
protected BaseWriteCommandMessage writeTheWrites(final BsonOutput bsonOutput, final int commandStartPosition, final BsonBinaryWriter writer) {
    DeleteCommandMessage nextMessage = null;
    writer.writeStartArray("deletes");
    for (int i = 0; i < deletes.size(); i++) {
        writer.mark();
        DeleteRequest deleteRequest = deletes.get(i);
        writer.writeStartDocument();
        writer.pushMaxDocumentSize(getSettings().getMaxDocumentSize());
        writer.writeName("q");
        getCodec(deleteRequest.getFilter()).encode(writer, deleteRequest.getFilter(), EncoderContext.builder().build());
        writer.writeInt32("limit", deleteRequest.isMulti() ? 0 : 1);
        if (deleteRequest.getCollation() != null) {
            writer.writeName("collation");
            BsonDocument collation = deleteRequest.getCollation().asDocument();
            getCodec(collation).encode(writer, collation, EncoderContext.builder().build());
        }
        writer.popMaxDocumentSize();
        writer.writeEndDocument();
        if (exceedsLimits(bsonOutput.getPosition() - commandStartPosition, i + 1)) {
            writer.reset();
            nextMessage = new DeleteCommandMessage(getWriteNamespace(), isOrdered(), getWriteConcern(), getSettings(), deletes.subList(i, deletes.size()));
            break;
        }
    }
    writer.writeEndArray();
    return nextMessage;
}
Also used : BsonDocument(org.bson.BsonDocument) DeleteRequest(com.mongodb.bulk.DeleteRequest)

Aggregations

DeleteRequest (com.mongodb.bulk.DeleteRequest)7 UpdateRequest (com.mongodb.bulk.UpdateRequest)4 WriteRequest (com.mongodb.bulk.WriteRequest)4 InsertRequest (com.mongodb.bulk.InsertRequest)2 Collation (com.mongodb.client.model.Collation)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 MixedBulkWriteOperation (com.mongodb.operation.MixedBulkWriteOperation)2 ArrayList (java.util.ArrayList)2 CollectibleCodec (org.bson.codecs.CollectibleCodec)2 AsyncConnection (com.mongodb.connection.AsyncConnection)1 NoOpFieldNameValidator (com.mongodb.internal.validator.NoOpFieldNameValidator)1 DeleteOperation (com.mongodb.operation.DeleteOperation)1 FindAndDeleteOperation (com.mongodb.operation.FindAndDeleteOperation)1 BsonDocument (org.bson.BsonDocument)1