private void EnsureIndex(IMongoIndexKeys evtIndex, IMongoIndexOptions options) { if (!Collection.IndexExists(evtIndex)) { Collection.CreateIndex(evtIndex, options); } }
public MongoDbIndexBuilder ThenAdd <TEntity>(IMongoIndexKeys index, IMongoIndexOptions options = null) { Requires.NotNull(index, "index"); _indexes.Add(new MongoDbIndex(typeof(TEntity).Name, index, options.AsOption())); return(this); }
public void CreateIndex(IMongoIndexKeys keys, IMongoIndexOptions options = null) { if (options != null) { //there is the possibility that create index trow if an index with same name and //different options/keys is created try { _collection.CreateIndex(keys, options); } catch (MongoWriteConcernException ex) { //probably index extist with different options, lets check if name is specified var optionsDoc = options.ToBsonDocument(); String indexName; if (optionsDoc.Names.Contains("name")) { indexName = optionsDoc["name"].AsString; } else { //determine the index name from fields, fragile but works with this version of drivers indexName = GetIndexName(keys); } _collection.DropIndexByName(indexName); _collection.CreateIndex(keys, options); } } else { _collection.CreateIndex(keys); } }
private String GetIndexName(IMongoIndexKeys keys) { var keysdocument = keys.ToBsonDocument(); return(keysdocument .Select(k => k.Name + "_" + k.Value.ToString()) .Aggregate((s1, s2) => s1 + "_" + s2)); }
/// <summary> /// Creates the index. /// </summary> /// <param name="keys">The keys.Sample: new IndexKeysBuilder().Ascending( "---THE NAME OF THE FIELD---" ) </param> /// <param name="options"> /// The options. Sample: IndexOptions.SetName( "---THE NAME OF THE INDEX---" ).SetUnique( false /// ).SetBackground( true ) ) /// </param> public virtual void CreateIndex(IMongoIndexKeys keys, IMongoIndexOptions options) { if (!Collection.Exists()) { Collection.Database.CreateCollection(Collection.Name); } Collection.CreateIndex(keys, options); }
/// <summary> /// /// </summary> /// <param name="_table"></param> /// <param name="_columns"></param> /// <param name="_indexName"></param> public static void BuildNonuniqueIndex(MongoCollection _table, IEnumerable <string> _columns, string _indexName) { IMongoIndexKeys keys = GetIndexKeys(_columns); IMongoIndexOptions options = GetIndexOptions(_indexName, false); _table.CreateIndex(keys, options); }
public MongoDbIndex(string collectionName, IMongoIndexKeys index, Option <IMongoIndexOptions> options) { Requires.NotNull(collectionName, "collectionName"); Requires.NotNull(index, "index"); Requires.NotNull(options, "options"); CollectionName = collectionName; Index = index; IndexOptions = options; }
public override WriteConcernResult CreateIndex(IMongoIndexKeys keys, IMongoIndexOptions options) { var sw = new Stopwatch(); sw.Start(); var result = base.CreateIndex(keys, options); sw.Stop(); string commandString = options != null ? string.Format("db.{0}.ensureIndex(keys, options)\n\nkeys = {1}\n\noptions = {2}", Name, keys.ToBsonDocument(), options.ToBsonDocument()) : string.Format("db.{0}.ensureIndex(keys, options)\n\nkeys = {1}", Name, keys.ToBsonDocument()); ProfilerUtils.AddMongoTiming(commandString, sw.ElapsedMilliseconds, ExecuteType.Command); return(result); }
public static Task EnsureIndexAsync(this MongoCollection collection, IMongoIndexKeys keys) { var tcs = new TaskCompletionSource <bool>(); ThreadPool.QueueUserWorkItem(_ => { try { collection.EnsureIndex(keys); tcs.SetResult(true); } catch (Exception exc) { tcs.SetException(exc); } }); return(tcs.Task); }
/// <summary> /// Ensures that the desired indexes exist and creates them if they don't exist. /// </summary> /// <param name="keys">The indexed fields.</param> /// <param name="options">The index options.</param> /// <remarks> /// This method allows ultimate control but does "leak" some MongoDb specific implementation details. /// </remarks> public virtual void EnsureIndexes(IMongoIndexKeys keys, IMongoIndexOptions options) { throw new NotImplementedException(); //var index = new IndexKeysDefinition<T>().Render() //collection.Indexes.CreateOneAsync(Builders<T>.IndexKeys.Text(a=>a.) }
public void EnsureIndexes(IMongoIndexKeys indexKeys, IMongoIndexOptions indexOptions) { Collection.EnsureIndex(indexKeys, indexOptions); }
/// <summary> /// Tests whether an index exists. /// </summary> /// <param name="keys">The indexed fields (usually an IndexKeysDocument or constructed using the IndexKeys builder).</param> /// <returns>True if the index exists.</returns> public virtual bool IndexExists(IMongoIndexKeys keys) { return(_collection.IndexExists(keys)); }
/// <summary> /// Drops an index on this collection. /// </summary> /// <param name="keys">The indexed fields (usually an IndexKeysDocument or constructed using the IndexKeys builder).</param> /// <returns>A <see cref="CommandResult"/>.</returns> public virtual CommandResult DropIndex(IMongoIndexKeys keys) { return(_collection.DropIndex(keys)); }
public bool IndexExists(IMongoIndexKeys keys) { return(_storage.IndexExists(keys)); }
public static Task <Boolean> IndexExistsAsync(this MongoCollection collection, IMongoIndexKeys keys) { var tcs = new TaskCompletionSource <Boolean>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.IndexExists(keys); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return(tcs.Task); }
private static void EnsureIndexInternal(IMongoIndexKeys indexKeys, bool unique) { GetCollection().EnsureIndex(indexKeys, IndexOptions.SetUnique(unique)); }
public static void EnsureIndex <TProperty1, TProperty2, TProperty3>(Expression <Func <T, TProperty1> > expression1, Expression <Func <T, TProperty2> > expression2, Expression <Func <T, TProperty3> > expression3, bool unique) { IMongoIndexKeys indexKeys = IndexKeys.Ascending(ExpressionUtility.GetPropertyName(expression1), ExpressionUtility.GetPropertyName(expression2), ExpressionUtility.GetPropertyName(expression3)); EnsureIndexInternal(indexKeys, unique); }
public static void EnsureIndex <TProperty>(Expression <Func <T, TProperty> > expression, bool unique) { IMongoIndexKeys indexKeys = IndexKeys.Ascending(ExpressionUtility.GetPropertyName(expression)); EnsureIndexInternal(indexKeys, unique); }
/// <summary> /// 해당 인덱스가 존재하지 않으면 새로 생성합니다. /// </summary> /// <param name="repository">MongRepository 인스턴스</param> /// <param name="keys"></param> /// <param name="options"></param> public static void EnsureIndex(this IMongoRepository repository, IMongoIndexKeys keys, IMongoIndexOptions options) { repository.Collection.EnsureIndex(keys, options); }
/// <summary> /// 인덱스 제거 /// </summary> /// <param name="repository">MongRepository 인스턴스</param> /// <param name="keys">인덱스 키</param> /// <returns></returns> public static CommandResult DropIndex(this IMongoRepository repository, IMongoIndexKeys keys) { return repository.Collection.DropIndex(keys); }
/// <summary> /// 인덱스를 생성합니다. /// </summary> /// <param name="repository">MongRepository 인스턴스</param> /// <param name="keys">인덱스 키</param> public static void CreateIndex(this IMongoRepository repository, IMongoIndexKeys keys) { repository.Collection.CreateIndex(keys); }
public void CreateIndex(IMongoIndexKeys keys, IMongoIndexOptions options = null) { _storage.CreateIndex(keys, options); }
/// <summary> /// Ensures that the desired indexes exist and creates them if they don't exist. /// </summary> /// <param name="keys">The indexed fields.</param> /// <param name="options">The index options.</param> /// <remarks> /// This method allows ultimate control but does "leak" some MongoDb specific implementation details. /// </remarks> public virtual void EnsureIndexes(IMongoIndexKeys keys, IMongoIndexOptions options) { this.collection.CreateIndex(keys, options); }
/// <summary> /// Creates an index for this collection. /// </summary> /// <param name="keys">The indexed fields (usually an IndexKeysDocument or constructed using the IndexKeys builder).</param> /// <returns>A SafeModeResult.</returns> public virtual SafeModeResult CreateIndex(IMongoIndexKeys keys) { return(CreateIndex(keys, IndexOptions.Null)); }
public SafeModeResult CreateIndex(IMongoIndexKeys keys) { return(_collection.CreateIndex(keys)); }
/// <summary> /// Ensures that the desired index exists and creates it if it does not. /// </summary> /// <param name="keys">The indexed fields (usually an IndexKeysDocument or constructed using the IndexKeys builder).</param> public virtual void EnsureIndex(IMongoIndexKeys keys) { _collection.EnsureIndex(keys); }
/// <summary> /// 해당 인덱스가 존재하지 않으면 새로 생성합니다. /// </summary> /// <param name="repository">MongRepository 인스턴스</param> /// <param name="keys"></param> public static void EnsureIndex(this IMongoRepository repository, IMongoIndexKeys keys) { repository.Collection.EnsureIndex(keys); }
/// <summary> /// Creates an index for this collection. /// </summary> /// <param name="keys">The indexed fields (usually an IndexKeysDocument or constructed using the IndexKeys builder).</param> /// <param name="options">The index options(usually an IndexOptionsDocument or created using the IndexOption builder).</param> /// <returns>A SafeModeResult.</returns> public virtual SafeModeResult CreateIndex(IMongoIndexKeys keys, IMongoIndexOptions options) { return(_collection.CreateIndex(keys, options)); }
public static Task <SafeModeResult> CreateIndexAsync(this MongoCollection collection, IMongoIndexKeys keys) { var tcs = new TaskCompletionSource <SafeModeResult>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.CreateIndex(keys); tcs.SetResult(result); } catch (Exception exc) { tcs.SetException(exc); } }); return(tcs.Task); }
/// <summary> /// 인덱스를 생성합니다. /// </summary> /// <param name="repository">MongRepository 인스턴스</param> /// <param name="keys">인덱스 키</param> /// <param name="options">인덱스 옵션</param> public static void CreateIndex(this IMongoRepository repository, IMongoIndexKeys keys, IMongoIndexOptions options) { repository.Collection.CreateIndex(keys, options); }
/// <summary> /// 인덱스 제거 /// </summary> /// <param name="repository">MongRepository 인스턴스</param> /// <param name="keys">인덱스 키</param> /// <returns></returns> public static CommandResult DropIndex(this IMongoRepository repository, IMongoIndexKeys keys) { return(repository.Collection.DropIndex(keys)); }
public void EnsureIndex <T>(IMongoIndexKeys keys, IMongoIndexOptions options) { GetCollection <T>().EnsureIndex(keys, options); }
public void EnsureIndex(IMongoIndexKeys keys, IMongoIndexOptions options) { _collection.EnsureIndex(keys, options); }