当前位置: 首页>>代码示例>>C#>>正文


C# MongoCollection.GetIndexes方法代码示例

本文整理汇总了C#中MongoCollection.GetIndexes方法的典型用法代码示例。如果您正苦于以下问题:C# MongoCollection.GetIndexes方法的具体用法?C# MongoCollection.GetIndexes怎么用?C# MongoCollection.GetIndexes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MongoCollection的用法示例。


在下文中一共展示了MongoCollection.GetIndexes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Open

        // 初始化
        // parameters:
        public int Open(
            // string strMongoDbConnStr,
            MongoClient client,
            string strInstancePrefix,
            out string strError)
        {
            strError = "";

#if NO
            if (string.IsNullOrEmpty(strMongoDbConnStr) == true)
            {
                strError = "strMongoDbConnStr 参数值不应为空";
                return -1;
            }
#endif

            if (string.IsNullOrEmpty(strInstancePrefix) == false)
                strInstancePrefix = strInstancePrefix + "_";

            _logDatabaseName = strInstancePrefix + "accessLog";

#if NO
            try
            {
                this._mongoClient = new MongoClient(strMongoDbConnStr);
            }
            catch (Exception ex)
            {
                strError = "初始化 MongoClient 时出错: " + ex.Message;
                return -1;
            }
#endif

            var server = client.GetServer();

            {
                var db = server.GetDatabase(this._logDatabaseName);

                _logCollection = db.GetCollection<AccessLogItem>("accessLog");
                // _logCollection.DropAllIndexes();
                if (_logCollection.GetIndexes().Count == 0)
                {
#if NO
                    _logCollection.CreateIndex(new IndexKeysBuilder().Ascending("OperTime"),
                        IndexOptions.SetUnique(false));
#endif
                    CreateIndex();
                }
            }

            _itemCount = new DailyItemCount();
            string date = GetToday();
            _itemCount.SetValue(date, GetItemCount(date));
            return 0;
        }
开发者ID:renyh1013,项目名称:dp2,代码行数:57,代码来源:AccessLogDatabase.cs

示例2: MongoDbPessimisticLocker

        internal MongoDbPessimisticLocker(MongoDatabase database, int ttl, bool dropCollection)
        {
            locks = database.GetCollection<PessimisticLockDto>("PessimisticLocks");
            if (dropCollection)
                locks.Drop();

            var indexes = locks.GetIndexes().ToArray();
            var tsIndex = indexes.FirstOrDefault(x => x.Name != "ts");
            if (tsIndex == null)
            {
                locks.CreateIndex(new IndexKeysBuilder().Ascending("ts"),
                    new IndexOptionsBuilder().SetTimeToLive(TimeSpan.FromSeconds(ttl)).SetName("ts"));
            }
            locks.CreateIndex(new IndexKeysBuilder().Ascending("kid"), new IndexOptionsBuilder().SetUnique(false));
        }
开发者ID:vedmiediev,项目名称:SimpleLeaderElection,代码行数:15,代码来源:MongoDbPessimisticLocker.cs

示例3: Open

        // 初始化
        // parameters:
        public int Open(
            // string strMongoDbConnStr,
            MongoClient client,
            string strInstancePrefix,
            out string strError)
        {
            strError = "";

#if NO
            if (string.IsNullOrEmpty(strMongoDbConnStr) == true)
            {
                strError = "strMongoDbConnStr 参数值不应为空";
                return -1;
            }
#endif

            if (string.IsNullOrEmpty(strInstancePrefix) == false)
                strInstancePrefix = strInstancePrefix + "_";

            m_strHitCountDatabaseName = strInstancePrefix + "hitcount";

#if NO
            try
            {
                this.m_mongoClient = new MongoClient(strMongoDbConnStr);
            }
            catch (Exception ex)
            {
                strError = "初始化 MongoClient 时出错: " + ex.Message;
                return -1;
            }
#endif

            var server = client.GetServer();

            {
                var db = server.GetDatabase(this.m_strHitCountDatabaseName);

                _hitCountCollection = db.GetCollection<HitCountItem>("hitcount");
                if (_hitCountCollection.GetIndexes().Count == 0)
                    CreateIndex();
            }

            return 0;
        }
开发者ID:renyh1013,项目名称:dp2,代码行数:47,代码来源:HitCountDatabase.cs

示例4: CreateIndex

        /// <summary>
        /// 创建索引
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="v"></param>
        private void CreateIndex(MongoCollection collection, Variant v)
        {
            var indexs = collection.GetIndexes();
            HashSet<string> hs = new HashSet<string>();
            foreach (IndexInfo index in indexs)
            {
                hs.Add(index.Name);
            }
            foreach (var item in v)
            {
                string indexName = item.Key;
                Variant keys = item.Value as Variant;
                if (keys != null)
                {
                    IndexOptionsBuilder indexOpt = new IndexOptionsBuilder();
                    indexOpt.SetName(indexName);
                    if (keys.ContainsKey("dropDups"))
                    {
                        if (keys["dropDups"] is bool)
                        {
                            indexOpt.SetDropDups((bool)keys["dropDups"]);
                        }
                        keys.Remove("dropDups");
                    }

                    if (keys.ContainsKey("background"))
                    {
                        if (keys["background"] is bool)
                        {
                            indexOpt.SetBackground((bool)keys["background"]);
                        }
                        keys.Remove("background");
                    }

                    if (keys.ContainsKey("unique"))
                    {
                        if (keys["unique"] is bool)
                        {
                            indexOpt.SetUnique((bool)keys["unique"]);
                        }
                        keys.Remove("unique");
                    }

                    if (keys.ContainsKey("sparse"))
                    {
                        if (keys["sparse"] is bool)
                        {
                            indexOpt.SetSparse((bool)keys["sparse"]);
                        }
                        keys.Remove("sparse");
                    }

                    bool find = false;
                    IndexKeysBuilder indexKey = new IndexKeysBuilder();
                    foreach (var dsa in keys)
                    {
                        string ckey = dsa.Key;
                        if (ckey != string.Empty && dsa.Value is int)
                        {
                            int dec = (int)dsa.Value;
                            if (dec == 1)
                            {
                                indexKey.Ascending(ckey);
                                find = true;
                            }
                            else if (dec == -1)
                            {
                                indexKey.Descending(ckey);
                                find = true;
                            }
                        }
                    }
                    if (find)
                    {
                        if (!hs.Contains(indexName))
                            collection.CreateIndex(indexKey, indexOpt);
                    }
                    else
                    {
                        if (hs.Contains(indexName))
                            collection.DropIndexByName(indexName);
                    }
                }
            }
        }
开发者ID:abel,项目名称:sinan,代码行数:90,代码来源:IndexCreater.cs


注:本文中的MongoCollection.GetIndexes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。