本文整理汇总了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);
}
示例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);
}
}
示例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;
}
示例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);
}
}
}
}