static void Pull(BsonDocument document, string name, BsonValue value, bool all) { var r = document.ResolvePath(name); if (r == null) return; BsonValue vArray; if (r.Array != null) vArray = r.Array[r.Index]; else if (!r.Document.TryGetValue(r.Key, out vArray)) return; if (vArray.BsonType != BsonType.Array) throw new InvalidOperationException(string.Format(null, @"Value ""{0}"" must be array.", name)); var array = vArray.AsBsonArray; if (!all && value.BsonType == BsonType.Document) { //_131130_103226 Created in Update.Pull(query) var wrapper = value as BsonDocumentWrapper; if (wrapper != null) value = (BsonValue)wrapper.WrappedObject; var predicate = QueryCompiler.GetFunction(value.AsBsonDocument); for (int i = array.Count; --i >= 0; ) { var v = array[i]; if (v.BsonType == BsonType.Document && predicate(v.AsBsonDocument)) array.RemoveAt(i); } } else { BsonArray values = all ? value.AsBsonArray : null; for (int i = array.Count; --i >= 0; ) { if (values == null) { if (value.CompareTo(array[i]) == 0) array.RemoveAt(i); } else { if (values.ContainsByCompareTo(array[i])) array.RemoveAt(i); } } } }
internal static bool GteComparer(BsonValue lhs, BsonValue rhs) => lhs.CompareTo(rhs) >= 0;
internal static bool LtComparer(BsonValue lhs, BsonValue rhs) => lhs.CompareTo(rhs) < 0;
internal static bool EqComparer(BsonValue lhs, BsonValue rhs) => lhs.CompareTo(rhs) == 0;