private void EnsureIndex(IMongoIndexKeys evtIndex, IMongoIndexOptions options)
 {
     if (!Collection.IndexExists(evtIndex))
     {
         Collection.CreateIndex(evtIndex, options);
     }
 }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
 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);
     }
 }
Exemplo n.º 4
0
        private String GetIndexName(IMongoIndexKeys keys)
        {
            var keysdocument = keys.ToBsonDocument();

            return(keysdocument
                   .Select(k => k.Name + "_" + k.Value.ToString())
                   .Aggregate((s1, s2) => s1 + "_" + s2));
        }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 6
0
        /// <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);
        }
Exemplo n.º 7
0
        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;
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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.)
 }
Exemplo n.º 11
0
 public void EnsureIndexes(IMongoIndexKeys indexKeys, IMongoIndexOptions indexOptions)
 {
     Collection.EnsureIndex(indexKeys, indexOptions);
 }
Exemplo n.º 12
0
 /// <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));
 }
Exemplo n.º 13
0
 /// <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));
 }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
 private static void EnsureIndexInternal(IMongoIndexKeys indexKeys, bool unique)
 {
     GetCollection().EnsureIndex(indexKeys, IndexOptions.SetUnique(unique));
 }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        public static void EnsureIndex <TProperty>(Expression <Func <T, TProperty> > expression, bool unique)
        {
            IMongoIndexKeys indexKeys = IndexKeys.Ascending(ExpressionUtility.GetPropertyName(expression));

            EnsureIndexInternal(indexKeys, unique);
        }
Exemplo n.º 19
0
 /// <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);
 }
Exemplo n.º 20
0
 /// <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);
 }
Exemplo n.º 21
0
 /// <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);
 }
Exemplo n.º 23
0
 /// <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);
 }
Exemplo n.º 24
0
 /// <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));
 }
Exemplo n.º 25
0
 public SafeModeResult CreateIndex(IMongoIndexKeys keys)
 {
     return(_collection.CreateIndex(keys));
 }
Exemplo n.º 26
0
 /// <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);
 }
Exemplo n.º 27
0
 /// <summary>
 /// 해당 인덱스가 존재하지 않으면 새로 생성합니다.
 /// </summary>
 /// <param name="repository">MongRepository 인스턴스</param>
 /// <param name="keys"></param>
 public static void EnsureIndex(this IMongoRepository repository, IMongoIndexKeys keys)
 {
     repository.Collection.EnsureIndex(keys);
 }
Exemplo n.º 28
0
 /// <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));
 }
Exemplo n.º 29
0
        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);
        }
Exemplo n.º 30
0
 /// <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);
 }
Exemplo n.º 31
0
 /// <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));
 }
Exemplo n.º 32
0
 public void EnsureIndex <T>(IMongoIndexKeys keys, IMongoIndexOptions options)
 {
     GetCollection <T>().EnsureIndex(keys, options);
 }
Exemplo n.º 33
0
 public void EnsureIndex(IMongoIndexKeys keys, IMongoIndexOptions options)
 {
     _collection.EnsureIndex(keys, options);
 }