static Expression PushExpression(Expression that, Expression field, BsonValue value) { if (value.BsonType == BsonType.Document) { var d = value.AsBsonDocument; if (d.Contains("$each")) { return(PushEachExpression(that, field, d)); } } value.ValidateNames(); return(Expression.Call(that, GetMethod("Push"), Data, field, Expression.Constant(value, typeof(BsonValue)))); }
UpdateCompiler Set(BsonDocument document, string name, BsonValue value) { value.ValidateNames(); 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); }
static Expression AddToSetExpression(Expression that, Expression field, BsonValue value) { bool addEach = false; if (value.BsonType == BsonType.Document) { var d = value.AsBsonDocument; if (d.ElementCount == 1) { var e = d.ElementAt(0); if (e.Name == "$each") { addEach = true; value = e.Value; } } } value.ValidateNames(); return(Expression.Call(that, GetMethod("AddToSet"), Data, field, Expression.Constant(value, typeof(BsonValue)), Expression.Constant(addEach, typeof(bool)))); }
UpdateCompiler Min(BsonDocument document, string name, BsonValue value) { value.ValidateNames(); var r = document.EnsurePath(name); if (r.Document != null) { BsonValue old; if (!r.Document.TryGetValue(r.Key, out old) || value.CompareTo(old) < 0) { r.Document[r.Key] = value; } } else if (!r.Array.InsertOutOfRange(r.Index, () => value)) { if (value.CompareTo(r.Array[r.Index]) < 0) { r.Array[r.Index] = value; } } return(this); }