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);
}
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;
}
Aggregations