Search in sources :

Example 6 with IndexOptionDefaults

use of com.mongodb.client.model.IndexOptionDefaults in project mongo-java-driver by mongodb.

the class MongoDatabaseImpl method executeCreateCollection.

private void executeCreateCollection(@Nullable final ClientSession clientSession, final String collectionName, final CreateCollectionOptions createCollectionOptions) {
    CreateCollectionOperation operation = new CreateCollectionOperation(name, collectionName, writeConcern).collation(createCollectionOptions.getCollation()).capped(createCollectionOptions.isCapped()).sizeInBytes(createCollectionOptions.getSizeInBytes()).maxDocuments(createCollectionOptions.getMaxDocuments()).storageEngineOptions(toBsonDocument(createCollectionOptions.getStorageEngineOptions())).expireAfter(createCollectionOptions.getExpireAfter(TimeUnit.SECONDS)).timeSeriesOptions(createCollectionOptions.getTimeSeriesOptions());
    IndexOptionDefaults indexOptionDefaults = createCollectionOptions.getIndexOptionDefaults();
    Bson storageEngine = indexOptionDefaults.getStorageEngine();
    if (storageEngine != null) {
        operation.indexOptionDefaults(new BsonDocument("storageEngine", toBsonDocument(storageEngine)));
    }
    ValidationOptions validationOptions = createCollectionOptions.getValidationOptions();
    Bson validator = validationOptions.getValidator();
    if (validator != null) {
        operation.validator(toBsonDocument(validator));
    }
    if (validationOptions.getValidationLevel() != null) {
        operation.validationLevel(validationOptions.getValidationLevel());
    }
    if (validationOptions.getValidationAction() != null) {
        operation.validationAction(validationOptions.getValidationAction());
    }
    executor.execute(operation, readConcern, clientSession);
}
Also used : CreateCollectionOperation(com.mongodb.internal.operation.CreateCollectionOperation) BsonDocument(org.bson.BsonDocument) ValidationOptions(com.mongodb.client.model.ValidationOptions) IndexOptionDefaults(com.mongodb.client.model.IndexOptionDefaults) Bson(org.bson.conversions.Bson)

Aggregations

IndexOptionDefaults (com.mongodb.client.model.IndexOptionDefaults)6 ValidationOptions (com.mongodb.client.model.ValidationOptions)6 BsonDocument (org.bson.BsonDocument)6 CreateCollectionOperation (com.mongodb.internal.operation.CreateCollectionOperation)3 CreateCollectionOperation (com.mongodb.operation.CreateCollectionOperation)3 Bson (org.bson.conversions.Bson)2