public virtual async Task <string> CreateOneAsync(IndexKeysDefinition <TDocument> keys, CreateIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { var model = new CreateIndexModel <TDocument>(keys, options); var result = await CreateManyAsync(new[] { model }, cancellationToken).ConfigureAwait(false); return(result.Single()); }
public override Task CreateOneAsync(IndexKeysDefinition <TDocument> keys, CreateIndexOptions options, CancellationToken cancellationToken) { Ensure.IsNotNull(keys, "keys"); var keysDocument = keys.Render(_collection._documentSerializer, _collection._settings.SerializerRegistry); options = options ?? new CreateIndexOptions(); var request = new CreateIndexRequest(keysDocument) { Name = options.Name, Background = options.Background, Bits = options.Bits, BucketSize = options.BucketSize, DefaultLanguage = options.DefaultLanguage, ExpireAfter = options.ExpireAfter, LanguageOverride = options.LanguageOverride, Max = options.Max, Min = options.Min, Sparse = options.Sparse, SphereIndexVersion = options.SphereIndexVersion, StorageEngine = options.StorageEngine, TextIndexVersion = options.TextIndexVersion, Unique = options.Unique, Version = options.Version, Weights = options.Weights }; var operation = new CreateIndexesOperation(_collection._collectionNamespace, new[] { request }, _collection._messageEncoderSettings); return(_collection.ExecuteWriteOperation(operation, cancellationToken)); }
public virtual string CreateOne(IClientSessionHandle session, IndexKeysDefinition <TDocument> keys, CreateIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { var model = new CreateIndexModel <TDocument>(keys, options); var result = CreateMany(session, new[] { model }, cancellationToken); return(result.Single()); }
/// <summary> /// Initializes a new instance of the <see cref="ClusteredIndexOptions{TDocument}"/> class. /// </summary> public ClusteredIndexOptions() { _key = new BsonDocument { { "_id", 1 } }; _unique = true; }
/// <summary> /// Combines an existing index keys definition with a descending index key definition. /// </summary> /// <typeparam name="TDocument">The type of the document.</typeparam> /// <param name="keys">The keys.</param> /// <param name="field">The field.</param> /// <returns> /// A combined index keys definition. /// </returns> public static IndexKeysDefinition <TDocument> Descending <TDocument>(this IndexKeysDefinition <TDocument> keys, Expression <Func <TDocument, object> > field) { var builder = Builders <TDocument> .IndexKeys; return(builder.Combine(keys, builder.Descending(field))); }
/// <summary> /// Combines an existing index keys definition with a descending index key definition. /// </summary> /// <typeparam name="TDocument">The type of the document.</typeparam> /// <param name="keys">The keys.</param> /// <param name="field">The field.</param> /// <returns> /// A combined index keys definition. /// </returns> public static IndexKeysDefinition <TDocument> Descending <TDocument>(this IndexKeysDefinition <TDocument> keys, FieldDefinition <TDocument> field) { var builder = Builders <TDocument> .IndexKeys; return(builder.Combine(keys, builder.Descending(field))); }
/// <summary> /// Combines an existing index keys definition with a hashed index key definition. /// </summary> /// <typeparam name="TDocument">The type of the document.</typeparam> /// <param name="keys">The keys.</param> /// <param name="field">The field.</param> /// <returns> /// A combined index keys definition. /// </returns> public static IndexKeysDefinition <TDocument> Hashed <TDocument>(this IndexKeysDefinition <TDocument> keys, FieldDefinition <TDocument> field) { var builder = Builders <TDocument> .IndexKeys; return(builder.Combine(keys, builder.Hashed(field))); }
/// <summary> /// Combines an existing index keys definition with a 2dsphere index key definition. /// </summary> /// <typeparam name="TDocument">The type of the document.</typeparam> /// <param name="keys">The keys.</param> /// <param name="field">The field.</param> /// <returns> /// A combined index keys definition. /// </returns> public static IndexKeysDefinition <TDocument> Geo2DSphere <TDocument>(this IndexKeysDefinition <TDocument> keys, Expression <Func <TDocument, object> > field) { var builder = Builders <TDocument> .IndexKeys; return(builder.Combine(keys, builder.Geo2DSphere(field))); }
/// <summary> /// Combines an existing index keys definition with a 2dsphere index key definition. /// </summary> /// <typeparam name="TDocument">The type of the document.</typeparam> /// <param name="keys">The keys.</param> /// <param name="field">The field.</param> /// <returns> /// A combined index keys definition. /// </returns> public static IndexKeysDefinition <TDocument> Geo2DSphere <TDocument>(this IndexKeysDefinition <TDocument> keys, FieldDefinition <TDocument> field) { var builder = Builders <TDocument> .IndexKeys; return(builder.Combine(keys, builder.Geo2DSphere(field))); }
/// <summary> /// Combines an existing index keys definition with a geo haystack index key definition. /// </summary> /// <typeparam name="TDocument">The type of the document.</typeparam> /// <param name="keys">The keys.</param> /// <param name="field">The field.</param> /// <param name="additionalFieldName">Name of the additional field.</param> /// <returns> /// A combined index keys definition. /// </returns> public static IndexKeysDefinition <TDocument> GeoHaystack <TDocument>(this IndexKeysDefinition <TDocument> keys, Expression <Func <TDocument, object> > field, Expression <Func <TDocument, object> > additionalFieldName = null) { var builder = Builders <TDocument> .IndexKeys; return(builder.Combine(keys, builder.GeoHaystack(field, additionalFieldName))); }
/// <inheritdoc /> public abstract Task CreateOneAsync(IndexKeysDefinition <TDocument> keys, CreateIndexOptions options = null, CancellationToken cancellationToken = default(CancellationToken));
/// <summary> /// Initializes a new instance of the <see cref="CreateIndexModel{TDocument}"/> class. /// </summary> /// <param name="keys">The keys.</param> /// <param name="options">The options.</param> public CreateIndexModel(IndexKeysDefinition <TDocument> keys, CreateIndexOptions options = null) { _keys = Ensure.IsNotNull(keys, nameof(keys)); _options = CreateIndexOptions <TDocument> .CoercedFrom(options); }
/// <summary> /// Initializes a new instance of the <see cref="CreateIndexModel{TDocument}"/> class. /// </summary> /// <param name="keys">The keys.</param> /// <param name="options">The options.</param> public CreateIndexModel(IndexKeysDefinition <TDocument> keys, CreateIndexOptions options = null) { _keys = Ensure.IsNotNull(keys, "keys"); _options = options; }