public override FilterDefinition <T> Visit(CompareFilter <ClrValue> nodeIn, None args) { var propertyName = nodeIn.Path.ToString(); var value = nodeIn.Value.Value; switch (nodeIn.Operator) { case CompareOperator.Empty: return(Filter.Or( Filter.Exists(propertyName, false), Filter.Eq <object?>(propertyName, null), Filter.Eq <object?>(propertyName, string.Empty), Filter.Size(propertyName, 0))); case CompareOperator.Exists: return(Filter.And( Filter.Exists(propertyName, true), Filter.Ne <object?>(propertyName, null))); case CompareOperator.Matchs: return(Filter.Regex(propertyName, BuildMatchRegex(nodeIn))); case CompareOperator.StartsWith: return(Filter.Regex(propertyName, BuildRegex(nodeIn, s => "^" + s))); case CompareOperator.Contains: return(Filter.Regex(propertyName, BuildRegex(nodeIn, s => s))); case CompareOperator.EndsWith: return(Filter.Regex(propertyName, BuildRegex(nodeIn, s => s + "$"))); case CompareOperator.Equals: return(Filter.Eq(propertyName, value)); case CompareOperator.GreaterThan: return(Filter.Gt(propertyName, value)); case CompareOperator.GreaterThanOrEqual: return(Filter.Gte(propertyName, value)); case CompareOperator.LessThan: return(Filter.Lt(propertyName, value)); case CompareOperator.LessThanOrEqual: return(Filter.Lte(propertyName, value)); case CompareOperator.NotEquals: return(Filter.Ne(propertyName, value)); case CompareOperator.In: return(Filter.In(propertyName, ((IList)value !).OfType <object>())); } throw new NotSupportedException(); }
public PagedList <dynamic> GetSharedNodes(Guid userId, int pageNumber = 1, int pageSize = 20, bool isPublicOnly = false) { var filter = _filterBase & _builder.Eq("OwnedBy", userId) & _builder.Or( _builder.Eq("AccessPermissions.IsPublic", true), _builder.Not(_builder.Size("AccessPermissions.Users", 0)), _builder.Not(_builder.Size("AccessPermissions.Groups", 0)) ); if (isPublicOnly) { filter = filter & _builder.Eq("AccessPermissions.IsPublic", true); } var nodes = _nodes.Aggregate() .Lookup <BsonDocument, BsonDocument>(nameof(AccessPermissions), "_id", "_id", nameof(AccessPermissions)) .Unwind <dynamic>(nameof(AccessPermissions)) .Match(filter.Render(_nodes.DocumentSerializer, _nodes.Settings.SerializerRegistry)); return(PagedList(nodes, pageNumber, pageSize)); }
public object SizeEq(string arrayProperty, int value) { return(InternalBuilder.Size(arrayProperty, value)); }
// // 摘要: // Tests that the size of the named array is equal to some value (see $size). // // 参数: // name: // The name of the element to test. // // size: // The size to compare to. // // 返回结果: // The builder (so method calls can be chained). public static FilterDefinition <BsonDocument> Size(string name, int size) { return(filter.Size(name, size)); }