本文整理汇总了C#中BsonDocument.Count方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocument.Count方法的具体用法?C# BsonDocument.Count怎么用?C# BsonDocument.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonDocument
的用法示例。
在下文中一共展示了BsonDocument.Count方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BsonDocMethod
static async Task BsonDocMethod()
{
var doc = new BsonDocument
{
{"name", "Sanya" }
};
doc.Add("age", 30);
doc["profession"] = "hacker";
var nestedArray = new BsonArray();
nestedArray.Add(new BsonDocument("color", "red"));
doc.Add("array", nestedArray);
Console.WriteLine(1);
//Console.WriteLine(doc.TryGetElement("name", out name));
Console.WriteLine(doc.Count());
Console.WriteLine();
Console.WriteLine(doc.ContainsValue("Sanya"));
Console.WriteLine(doc.Contains("name"));
Console.WriteLine(doc);
//var doc2 = new BsonDocument
//{
// { "Name", "Smith"},
// {"Something", "something else" },
// {"profession", "hacker" }
//};
//await collectionUsed.InsertManyAsync(new[] { doc, doc2 });
}
示例2: 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;
}
示例3: CorrectDateField
private static BsonDocument CorrectDateField(BsonDocument bsonDocument)
{
BsonDocument result = new BsonDocument();
int cpt = bsonDocument.Count();
for (int i = 0; i < cpt; i++)
{
var element = bsonDocument.ElementAt(i);
var value = element.Value;
var name = element.Name;
if(value is BsonDocument)
{
value =CorrectDateField(value as BsonDocument);
element = new BsonElement(name, value);
}
else
{
DateTime Out;
if (DateTime.TryParse(value.ToString(), out Out))
{
value = new BsonDateTime(Out);
element = new BsonElement(name, value);
}
}
result.Add(element);
}
return result;
}