本文整理汇总了C#中BsonDocument.GetNestedValues方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocument.GetNestedValues方法的具体用法?C# BsonDocument.GetNestedValues怎么用?C# BsonDocument.GetNestedValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonDocument
的用法示例。
在下文中一共展示了BsonDocument.GetNestedValues方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Type
static bool Type(BsonDocument document, string name, BsonType type)
{
foreach (var data in document.GetNestedValues(name))
if (data.BsonType == type)
return true;
return false;
}
示例2: NE
static bool NE(BsonDocument document, string name, BsonValue value)
{
bool ok = false;
foreach (var data in document.GetNestedValues(name))
{
ok = true;
if (data.CompareTo(value) != 0)
return true;
}
return ok ? false : value.BsonType != BsonType.Null;
}
示例3: Size
// If missing or not a number then false.
// If value is not a number then size 0 is used instead.
// Why double: Mongo allows long and doubles and compares doubles with sizes literally.
static bool Size(BsonDocument document, string name, double size)
{
foreach (var data in document.GetNestedValues(name))
if (data.BsonType == BsonType.Array && data.AsBsonArray.Count == size)
return true;
return false;
}
示例4: Mod
// If missing or not a number then false else numbers are converted to long.
static bool Mod(BsonDocument document, string name, long divisor, long value)
{
foreach (var data in document.GetNestedValues(name))
{
switch (data.BsonType)
{
case BsonType.Int64:
if (data.AsInt64 % divisor == value)
return true;
break;
case BsonType.Int32:
if ((long)data.AsInt32 % divisor == value)
return true;
break;
case BsonType.Double:
if ((long)data.AsDouble % divisor == value)
return true;
break;
}
}
return false;
}
示例5: Matches
static bool Matches(BsonDocument document, string name, Regex regex)
{
if (regex == null)
return false;
foreach (var data in document.GetNestedValues(name))
if (data.BsonType == BsonType.String && regex.IsMatch(data.AsString))
return true;
return false;
}
示例6: In
static bool In(BsonDocument document, string name, BsonArray value)
{
foreach (var data in document.GetNestedValues(name))
{
if (data.BsonType != BsonType.Array)
if (value.FirstOrDefault(x => data.EqualsOrMatches(x)) != null)
return true;
else
continue;
foreach (var it in data.AsBsonArray)
if (value.FirstOrDefault(x => it.EqualsOrMatches(x)) != null)
return true;
}
return false;
}
示例7: ElemMatch
static bool ElemMatch(BsonDocument document, string name, Func<BsonDocument, bool> predicate)
{
foreach (var data in document.GetNestedValues(name))
{
if (data.BsonType != BsonType.Array)
continue;
foreach (var doc in data.AsBsonArray)
if (doc.BsonType == BsonType.Document && predicate(doc.AsBsonDocument))
return true;
}
return false;
}
示例8: All
// If the field is missing or the size is empty then false.
static bool All(BsonDocument document, string name, List<object> all)
{
if (all.Count == 0)
return false;
foreach (var data in document.GetNestedValues(name))
{
if (data.BsonType != BsonType.Array)
{
foreach (var one in all)
if (!data.EqualsOrElemMatches(one))
goto next;
return true;
}
foreach (var one in all)
if (data.AsBsonArray.FirstOrDefault(x => x.EqualsOrElemMatches(one)) == null)
goto next;
return true;
next: ;
}
return false;
}