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); }
private void EnsureIndex(IMongoIndexKeys evtIndex, IMongoIndexOptions options) { if (!Collection.IndexExists(evtIndex)) { Collection.CreateIndex(evtIndex, options); } }
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); } }
/// <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); }
public static void BuildGeospatialIndex(MongoCollection _table, string _column, string _indexName) { IndexKeysBuilder ikb = IndexKeys.GeoSpatialSpherical(_column); IMongoIndexOptions options = GetIndexOptions(_indexName, false); _table.CreateIndex(ikb, 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 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); }
/// <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)); }
/// <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> /// <param name="options">The index options(usually an IndexOptionsDocument or created using the IndexOption builder).</param> public virtual void EnsureIndex(IMongoIndexKeys keys, IMongoIndexOptions options) { _collection.EnsureIndex(keys, options); }
public void CreateIndex(IMongoIndexKeys keys, IMongoIndexOptions options = null) { _storage.CreateIndex(keys, options); }
public static Task EnsureIndexAsync(this MongoCollection collection, IMongoIndexKeys keys, IMongoIndexOptions options) { var tcs = new TaskCompletionSource <bool>(); ThreadPool.QueueUserWorkItem(_ => { try { collection.EnsureIndex(keys, options); tcs.SetResult(true); } 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> /// <param name="options"></param> public static void EnsureIndex(this IMongoRepository repository, IMongoIndexKeys keys, IMongoIndexOptions options) { repository.Collection.EnsureIndex(keys, options); }
public void EnsureIndexes(IMongoIndexKeys indexKeys, IMongoIndexOptions indexOptions) { Collection.EnsureIndex(indexKeys, indexOptions); }
public static Task <SafeModeResult> CreateIndexAsync(this MongoCollection collection, IMongoIndexKeys keys, IMongoIndexOptions options) { var tcs = new TaskCompletionSource <SafeModeResult>(); ThreadPool.QueueUserWorkItem(_ => { try { var result = collection.CreateIndex(keys, options); tcs.SetResult(result); } 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) { this.collection.CreateIndex(keys, options); }
public void EnsureIndex <T>(IMongoIndexKeys keys, IMongoIndexOptions options) { GetCollection <T>().EnsureIndex(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) { throw new NotImplementedException(); //var index = new IndexKeysDefinition<T>().Render() //collection.Indexes.CreateOneAsync(Builders<T>.IndexKeys.Text(a=>a.) }