本文整理汇总了C#中BsonDocument.EnsurePath方法的典型用法代码示例。如果您正苦于以下问题:C# BsonDocument.EnsurePath方法的具体用法?C# BsonDocument.EnsurePath怎么用?C# BsonDocument.EnsurePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonDocument
的用法示例。
在下文中一共展示了BsonDocument.EnsurePath方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Set
UpdateCompiler Set(BsonDocument document, string name, BsonValue value)
{
var r = document.EnsurePath(name);
if (r.Document != null)
{
r.Document[r.Key] = value;
}
else if (!r.Array.InsertOutOfRange(r.Index, () => value))
{
r.Array[r.Index] = value;
}
return this;
}
示例2: Rename
UpdateCompiler Rename(BsonDocument document, string name, string newName)
{
var r1 = document.ResolvePath(name, true); //_131028_234439 Weird, we can rename in arrays but follow Mongo that cannot.
if (r1 != null)
{
BsonValue value;
if (r1.Document.TryGetValue(r1.Key, out value))
{
var r2 = document.EnsurePath(newName);
r1.Document.Remove(r1.Key);
r2.Document[r2.Key] = value;
}
}
return this;
}
示例3: AddToSet
UpdateCompiler AddToSet(BsonDocument document, string name, BsonValue value, bool each)
{
var r = document.EnsurePath(name);
BsonValue vArray;
if (r.Array != null)
{
if (r.Array.InsertOutOfRange(r.Index, () => new BsonArray() { value }))
return this;
vArray = r.Array[r.Index];
}
else if (!r.Document.TryGetValue(r.Key, out vArray))
{
r.Document.Add(r.Key, new BsonArray() { value });
return this;
}
if (vArray.BsonType != BsonType.Array)
throw new InvalidOperationException(string.Format(null, @"Value ""{0}"" must be array.", name));
if (each && value.BsonType == BsonType.Array)
vArray.AsBsonArray.AddToSetEach(value.AsBsonArray);
else
vArray.AsBsonArray.AddToSet(value);
return this;
}
示例4: Inc
UpdateCompiler Inc(BsonDocument document, string name, BsonValue value)
{
var r = document.EnsurePath(name);
BsonValue old;
if (r.Document != null)
{
if (r.Document.TryGetValue(r.Key, out old))
{
if (!old.IsNumeric)
throw new MongoException(string.Format(null, @"Field ""{0}"" must be numeric.", name));
value = MyValue.Add(old, value);
}
r.Document[r.Key] = value;
}
else if (!r.Array.InsertOutOfRange(r.Index, () => value))
{
old = r.Array[r.Index];
if (!old.IsNumeric)
throw new MongoException(string.Format(null, @"Item ""{0}"" must be numeric.", name));
r.Array[r.Index] = MyValue.Add(old, value);
}
return this;
}
示例5: Push
static void Push(BsonDocument document, string name, BsonValue value, bool all)
{
var r = document.EnsurePath(name);
BsonValue v2 = BsonNull.Value;
if (r.Array != null)
{
if (!r.Array.InsertOutOfRange(r.Index, () => v2 = new BsonArray()))
v2 = r.Array[r.Index];
}
else if (!r.Document.TryGetValue(r.Key, out v2))
{
v2 = new BsonArray();
r.Document.Add(r.Key, v2);
}
if (v2.BsonType != BsonType.Array)
throw new InvalidOperationException(string.Format(null, @"Value ""{0}"" must be array.", name));
var array = v2.AsBsonArray;
if (all)
array.AddRange(value.AsBsonArray);
else
array.Add(value);
}