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


C# MongoCollection.DropIndexByName方法代码示例

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


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

示例1: UpdateDocument

        public override void UpdateDocument(MongoCollection<BsonDocument> collection, BsonDocument document) {
            if (collection.IndexExistsByName("Username_1"))
                collection.DropIndexByName("Username_1");

            if (document.Contains("Username"))
                document.Remove("Username");

            collection.Save(document);
        }
开发者ID:Ripper555,项目名称:Exceptionless,代码行数:9,代码来源:v1.0.16.cs

示例2: Drop

 public void Drop(MongoCollection collection)
 {
     if (Exists(collection))
     {
         log.Info("Dropping index {0} from collection {1}",name,collection.Name);
         collection.DropIndexByName(name);
     }
     else
     {
         log.Info("Index {0} does not exist on collection {1}, dropping skipped",name,collection.Name);
     }
 }
开发者ID:BernhardGlueck,项目名称:Phare,代码行数:12,代码来源:IndexDefinition.cs

示例3: DropMongoIndex

 /// <summary>
 ///     删除索引[KEY_ID]以外
 /// </summary>
 /// <param name="indexName"></param>
 /// <param name="mongoCol"></param>
 /// <returns></returns>
 public static bool DropMongoIndex(string indexName, MongoCollection mongoCol)
 {
     if (indexName == ConstMgr.KeyId)
     {
         return false;
     }
     if (mongoCol.IndexExistsByName(indexName))
     {
         mongoCol.DropIndexByName(indexName);
     }
     return true;
 }
开发者ID:jango2015,项目名称:MongoCola,代码行数:18,代码来源:Collection.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.DropIndexByName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。