/* Copyright 2010-present MongoDB Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
namespace MongoDB.Driver
{
///
/// Options for creating a collection.
///
public class CreateCollectionOptions
{
// fields
private bool? _autoIndexId;
private bool? _capped;
private Collation _collation;
private IndexOptionDefaults _indexOptionDefaults;
private long? _maxDocuments;
private long? _maxSize;
private bool? _noPadding;
private BsonDocument _storageEngine;
private bool? _usePowerOf2Sizes;
private IBsonSerializerRegistry _serializerRegistry;
private DocumentValidationAction? _validationAction;
private DocumentValidationLevel? _validationLevel;
// properties
///
/// Gets or sets the collation.
///
public Collation Collation
{
get { return _collation; }
set { _collation = value; }
}
///
/// Gets or sets a value indicating whether to automatically create an index on the _id.
///
[Obsolete("AutoIndexId has been deprecated since server version 3.2.")]
public bool? AutoIndexId
{
get { return _autoIndexId; }
set { _autoIndexId = value; }
}
///
/// Gets or sets a value indicating whether the collection is capped.
///
public bool? Capped
{
get { return _capped; }
set { _capped = value; }
}
///
/// Gets or sets the index option defaults.
///
///
/// The index option defaults.
///
public IndexOptionDefaults IndexOptionDefaults
{
get { return _indexOptionDefaults; }
set { _indexOptionDefaults = value; }
}
///
/// Gets or sets the maximum number of documents (used with capped collections).
///
public long? MaxDocuments
{
get { return _maxDocuments; }
set { _maxDocuments = value; }
}
///
/// Gets or sets the maximum size of the collection (used with capped collections).
///
public long? MaxSize
{
get { return _maxSize; }
set { _maxSize = value; }
}
///
/// Gets or sets whether padding should not be used.
///
public bool? NoPadding
{
get { return _noPadding; }
set { _noPadding = value; }
}
///
/// Gets or sets the serializer registry.
///
public IBsonSerializerRegistry SerializerRegistry
{
get { return _serializerRegistry; }
set { _serializerRegistry = value; }
}
///
/// Gets or sets the storage engine options.
///
public BsonDocument StorageEngine
{
get { return _storageEngine; }
set { _storageEngine = value; }
}
///
/// Gets or sets a value indicating whether to use power of 2 sizes.
///
public bool? UsePowerOf2Sizes
{
get { return _usePowerOf2Sizes; }
set { _usePowerOf2Sizes = value; }
}
///
/// Gets or sets the validation action.
///
///
/// The validation action.
///
public DocumentValidationAction? ValidationAction
{
get { return _validationAction; }
set { _validationAction = value; }
}
///
/// Gets or sets the validation level.
///
///
/// The validation level.
///
public DocumentValidationLevel? ValidationLevel
{
get { return _validationLevel; }
set { _validationLevel = value; }
}
}
///
/// Options for creating a collection.
///
/// The type of the document.
public sealed class CreateCollectionOptions : CreateCollectionOptions
{
#region static
// internal static methods
///
/// Coerces a generic CreateCollectionOptions{TDocument} from a non-generic CreateCollectionOptions.
///
/// The options.
/// The generic options.
internal static CreateCollectionOptions CoercedFrom(CreateCollectionOptions options)
{
if (options == null)
{
return null;
}
if (options.GetType() == typeof(CreateCollectionOptions))
{
#pragma warning disable 618
return new CreateCollectionOptions
{
AutoIndexId = options.AutoIndexId,
Capped = options.Capped,
Collation = options.Collation,
IndexOptionDefaults = options.IndexOptionDefaults,
MaxDocuments = options.MaxDocuments,
MaxSize = options.MaxSize,
NoPadding = options.NoPadding,
SerializerRegistry = options.SerializerRegistry,
StorageEngine = options.StorageEngine,
UsePowerOf2Sizes = options.UsePowerOf2Sizes,
ValidationAction = options.ValidationAction,
ValidationLevel = options.ValidationLevel
};
#pragma warning restore
}
return (CreateCollectionOptions)options;
}
#endregion
// private fields
private IBsonSerializer _documentSerializer;
private FilterDefinition _validator;
// public properties
///
/// Gets or sets the document serializer.
///
public IBsonSerializer DocumentSerializer
{
get { return _documentSerializer; }
set { _documentSerializer = value; }
}
///
/// Gets or sets the validator.
///
///
/// The validator.
///
public FilterDefinition Validator
{
get { return _validator; }
set { _validator = value; }
}
}
}