Package com.mongodb.operation
Class CreateCollectionOperation
- java.lang.Object
-
- com.mongodb.operation.CreateCollectionOperation
-
- All Implemented Interfaces:
AsyncWriteOperation<java.lang.Void>,WriteOperation<java.lang.Void>
public class CreateCollectionOperation extends java.lang.Object implements AsyncWriteOperation<java.lang.Void>, WriteOperation<java.lang.Void>
An operation to create a collection- Since:
- 3.0
-
-
Constructor Summary
Constructors Constructor Description CreateCollectionOperation(java.lang.String databaseName, java.lang.String collectionName)Construct a new instance.CreateCollectionOperation(java.lang.String databaseName, java.lang.String collectionName, WriteConcern writeConcern)Construct a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description CreateCollectionOperationautoIndex(boolean autoIndex)Sets if _id field of the collection is indexed.CreateCollectionOperationcapped(boolean capped)Sets whether the collection is capped.CreateCollectionOperationcollation(Collation collation)Sets the collation optionsjava.lang.Voidexecute(WriteBinding binding)General execute which can return anything of type TvoidexecuteAsync(AsyncWriteBinding binding, SingleResultCallback<java.lang.Void> callback)General execute which can return anything of type TCollationgetCollation()Returns the collation optionsjava.lang.StringgetCollectionName()Gets the name of the collection to create.BsonDocumentgetIndexOptionDefaults()Gets the index option defaults for the collection.longgetMaxDocuments()Gets the maximum number of documents allowed in the collection.longgetSizeInBytes()Gets the maximum size of the collection in bytes.BsonDocumentgetStorageEngineOptions()Gets the storage engine options document for this collection.ValidationActiongetValidationAction()Gets theValidationAction.ValidationLevelgetValidationLevel()Gets theValidationLevelthat determines how strictly MongoDB applies the validation rules to existing documents during an insert or update.BsonDocumentgetValidator()Gets the validation rules for inserting or updating documentsWriteConcerngetWriteConcern()Gets the write concern.CreateCollectionOperationindexOptionDefaults(BsonDocument indexOptionDefaults)Sets the index option defaults document for the collection.booleanisAutoIndex()The auto index value.booleanisCapped()Gets whether the collection is capped.java.lang.BooleanisUsePowerOf2Sizes()Deprecated.As of MongoDB 3.0, power of 2 sizes is ignored by the MongoDB serverCreateCollectionOperationmaxDocuments(long maxDocuments)Set the maximum number of documents in the collection.CreateCollectionOperationsizeInBytes(long sizeInBytes)Sets the maximum size of the collection in bytes.CreateCollectionOperationstorageEngineOptions(BsonDocument storageEngineOptions)Sets the storage engine options document for this collection.CreateCollectionOperationusePowerOf2Sizes(java.lang.Boolean usePowerOf2Sizes)Deprecated.As of MongoDB 3.0, power of 2 sizes is ignored by the MongoDB serverCreateCollectionOperationvalidationAction(ValidationAction validationAction)Sets theValidationActionthat determines whether to error on invalid documents or just warn about the violations but allow invalid documents.CreateCollectionOperationvalidationLevel(ValidationLevel validationLevel)Sets the validation level that determines how strictly MongoDB applies the validation rules to existing documents during an insert or update.CreateCollectionOperationvalidator(BsonDocument validator)Sets the validation rules for inserting or updating documents
-
-
-
Constructor Detail
-
CreateCollectionOperation
public CreateCollectionOperation(java.lang.String databaseName, java.lang.String collectionName)Construct a new instance.- Parameters:
databaseName- the name of the database for the operation.collectionName- the name of the collection to be created.
-
CreateCollectionOperation
public CreateCollectionOperation(java.lang.String databaseName, java.lang.String collectionName, WriteConcern writeConcern)Construct a new instance.- Parameters:
databaseName- the name of the database for the operation.collectionName- the name of the collection to be created.writeConcern- the write concern- Since:
- 3.4
-
-
Method Detail
-
getCollectionName
public java.lang.String getCollectionName()
Gets the name of the collection to create.- Returns:
- the collection name
-
getWriteConcern
public WriteConcern getWriteConcern()
Gets the write concern.- Returns:
- the write concern, which may be null
- Since:
- 3.4
-
isAutoIndex
public boolean isAutoIndex()
The auto index value.- Returns:
- true if auto-index is enabled
-
autoIndex
public CreateCollectionOperation autoIndex(boolean autoIndex)
Sets if _id field of the collection is indexed. Only applies to capped collections and defaults to true.- Parameters:
autoIndex- true if auto-index of _id is enabled. Only applies to capped collections.- Returns:
- this
-
getMaxDocuments
public long getMaxDocuments()
Gets the maximum number of documents allowed in the collection.- Returns:
- max number of documents in the collection
-
maxDocuments
public CreateCollectionOperation maxDocuments(long maxDocuments)
Set the maximum number of documents in the collection. Only applies to capped collections- Parameters:
maxDocuments- the maximum number of documents in the collection. Only applies to capped collections.- Returns:
- this
-
isCapped
public boolean isCapped()
Gets whether the collection is capped.- Returns:
- whether the collection is capped
-
capped
public CreateCollectionOperation capped(boolean capped)
Sets whether the collection is capped. Capped collections also require the size set seesizeInBytes.- Parameters:
capped- whether the collection is capped. Defaults to false.- Returns:
- this
-
getSizeInBytes
public long getSizeInBytes()
Gets the maximum size of the collection in bytes.- Returns:
- the maximum size of the collection
-
sizeInBytes
public CreateCollectionOperation sizeInBytes(long sizeInBytes)
Sets the maximum size of the collection in bytes. Required for capped collections.- Parameters:
sizeInBytes- the maximum size of the collection- Returns:
- this
-
isUsePowerOf2Sizes
@Deprecated public java.lang.Boolean isUsePowerOf2Sizes()
Deprecated.As of MongoDB 3.0, power of 2 sizes is ignored by the MongoDB serverGets whether usePowerOf2Sizes should be used foe the allocation strategy.Note: usePowerOf2Sizes} became the default allocation strategy in mongodb 2.6
- Returns:
- usePowerOf2Sizes became the default allocation strategy
-
usePowerOf2Sizes
@Deprecated public CreateCollectionOperation usePowerOf2Sizes(java.lang.Boolean usePowerOf2Sizes)
Deprecated.As of MongoDB 3.0, power of 2 sizes is ignored by the MongoDB serverSets whether usePowerOf2Sizes should be used foe the allocation strategy.Note: usePowerOf2Sizes} became the default allocation strategy in mongodb 2.6
- Parameters:
usePowerOf2Sizes- as the default allocation strategy- Returns:
- this
-
getStorageEngineOptions
public BsonDocument getStorageEngineOptions()
Gets the storage engine options document for this collection.- Returns:
- the storage engine options
-
storageEngineOptions
public CreateCollectionOperation storageEngineOptions(BsonDocument storageEngineOptions)
Sets the storage engine options document for this collection.- Parameters:
storageEngineOptions- the storage engine options- Returns:
- this
-
getIndexOptionDefaults
public BsonDocument getIndexOptionDefaults()
Gets the index option defaults for the collection.- Returns:
- the index option defaults
- Since:
- 3.2
-
indexOptionDefaults
public CreateCollectionOperation indexOptionDefaults(BsonDocument indexOptionDefaults)
Sets the index option defaults document for the collection.- Parameters:
indexOptionDefaults- the index option defaults- Returns:
- this
- Since:
- 3.2
-
getValidator
public BsonDocument getValidator()
Gets the validation rules for inserting or updating documents- Returns:
- the validation rules if set or null
- Since:
- 3.2
-
validator
public CreateCollectionOperation validator(BsonDocument validator)
Sets the validation rules for inserting or updating documents- Parameters:
validator- the validation rules for inserting or updating documents- Returns:
- this
- Since:
- 3.2
-
getValidationLevel
public ValidationLevel getValidationLevel()
Gets theValidationLevelthat determines how strictly MongoDB applies the validation rules to existing documents during an insert or update.- Returns:
- the ValidationLevel if set or null
- Since:
- 3.2
-
validationLevel
public CreateCollectionOperation validationLevel(ValidationLevel validationLevel)
Sets the validation level that determines how strictly MongoDB applies the validation rules to existing documents during an insert or update.- Parameters:
validationLevel- the validation level- Returns:
- this
- Since:
- 3.2
-
getValidationAction
public ValidationAction getValidationAction()
Gets theValidationAction.- Returns:
- the ValidationAction if set or null
- Since:
- 3.2
-
validationAction
public CreateCollectionOperation validationAction(ValidationAction validationAction)
Sets theValidationActionthat determines whether to error on invalid documents or just warn about the violations but allow invalid documents.- Parameters:
validationAction- the validation action- Returns:
- this
- Since:
- 3.2
-
getCollation
public Collation getCollation()
Returns the collation options- Returns:
- the collation options
- Since:
- 3.4
-
collation
public CreateCollectionOperation collation(Collation collation)
Sets the collation optionsA null value represents the server default.
- Parameters:
collation- the collation options to use- Returns:
- this
- Since:
- 3.4
-
execute
public java.lang.Void execute(WriteBinding binding)
Description copied from interface:WriteOperationGeneral execute which can return anything of type T- Specified by:
executein interfaceWriteOperation<java.lang.Void>- Parameters:
binding- the binding to execute in the context of- Returns:
- T, the result of the execution
-
executeAsync
public void executeAsync(AsyncWriteBinding binding, SingleResultCallback<java.lang.Void> callback)
Description copied from interface:AsyncWriteOperationGeneral execute which can return anything of type T- Specified by:
executeAsyncin interfaceAsyncWriteOperation<java.lang.Void>- Parameters:
binding- the binding to execute in the context ofcallback- the callback to be called when the operation has been executed
-
-