本文整理匯總了C#中BsonDocument.Clear方法的典型用法代碼示例。如果您正苦於以下問題:C# BsonDocument.Clear方法的具體用法?C# BsonDocument.Clear怎麽用?C# BsonDocument.Clear使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類BsonDocument
的用法示例。
在下文中一共展示了BsonDocument.Clear方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: UpdateDocument
protected override void UpdateDocument(BsonDocument document, Func<BsonDocument, UpdateCompiler> update)
{
var copy = document.DeepClone();
try
{
update(document);
}
catch
{
document.Clear();
document.AddRange(copy.AsBsonDocument);
throw;
}
}
示例2: UpdateDocument
protected override void UpdateDocument(BsonDocument document, Func<BsonDocument, UpdateCompiler> update)
{
var oldId = document[MyValue.Id];
var copy = document.DeepClone();
try
{
update(document);
BsonValue newId;
if (!document.TryGetValue(MyValue.Id, out newId) || !oldId.Equals(newId))
throw new InvalidOperationException("Modification of _id is not allowed.");
}
catch
{
document.Clear();
document.AddRange(copy.AsBsonDocument);
throw;
}
}
示例3: PromoteQueryToDollarAndForm
private static void PromoteQueryToDollarAndForm(BsonDocument query, BsonElement clause)
{
var clauses = new BsonArray();
foreach (var queryElement in query)
{
clauses.Add(new BsonDocument(queryElement));
}
clauses.Add(new BsonDocument(clause));
query.Clear();
query.Add("$and", clauses);
}
示例4: TestClear
public void TestClear()
{
var document = new BsonDocument("x", 1);
Assert.AreEqual(1, document.ElementCount);
document.Clear();
Assert.AreEqual(0, document.ElementCount);
}
示例5: GetAggregation
/// <summary>
/// Aggregation用的$project和$order
/// </summary>
/// <returns></returns>
public List<BsonDocument> GetAggregation()
{
//如果有改名的話,則其他沒有改名的,也需要設定輸出
var projectAggr = new BsonDocument();
var suppressAggr = new BsonDocument();
var project = new BsonDocument();
var suppress = new BsonDocument();
bool HasRename = false;
foreach (var item in _mQueryFieldList)
{
var ctl = ((CtlFieldInfo)Controls.Find(item.ColName, true)[0]).QueryFieldItem;
if (ctl.ColName == ConstMgr.KeyId)
{
//id
if (!ctl.IsShow)
{
//id抑製
suppress.Add(new BsonElement(ConstMgr.KeyId, 0));
}
}
else
{
//其他字段
if (ctl.IsShow)
{
if (string.IsNullOrEmpty(ctl.ProjectName))
{
project.Add(new BsonElement(ctl.ColName, 1));
}
else
{
project.Add(new BsonElement(ctl.ProjectName, "$" + ctl.ColName));
HasRename = true;
}
}
else
{
suppress.Add(new BsonElement(ctl.ColName, 0));
}
}
}
var aggrDocList = new List<BsonDocument>();
//如果有抑製操作和改名操作,則需要分開執行
suppressAggr.Add(new BsonElement("$project", suppress));
aggrDocList.Add(suppressAggr);
if (!HasRename && suppress.Count() == 0)
{
//沒有改名和抑製的時候,則project全部去除
project.Clear();
}
projectAggr.Add(new BsonElement("$project", project));
aggrDocList.Add(projectAggr);
return aggrDocList;
}