Пример #1
0
        private bool TryTranslateAllResultOperator(PipelineExpression node, out BsonValue result)
        {
            var resultOperator = node.ResultOperator as AllResultOperator;

            if (resultOperator != null)
            {
                var whereExpression = node.Source as WhereExpression;

                if (whereExpression != null)
                {
                    var inValue = TranslateValue(FieldNamePrefixer.Prefix(whereExpression.Predicate, "$" + whereExpression.ItemName));

                    result = new BsonDocument("$map", new BsonDocument
                    {
                        { "input", TranslateValue(whereExpression.Source) },
                        { "as", whereExpression.ItemName },
                        { "in", inValue }
                    });

                    result = new BsonDocument("$allElementsTrue", result);
                    return(true);
                }
            }

            result = null;
            return(false);
        }
Пример #2
0
        private BsonValue TranslateWhere(WhereExpression node)
        {
            var inputValue = TranslateValue(node.Source);
            var condValue  = TranslateValue(FieldNamePrefixer.Prefix(node.Predicate, "$" + node.ItemName));

            return(new BsonDocument("$filter", new BsonDocument
            {
                { "input", inputValue },
                { "as", node.ItemName },
                { "cond", condValue }
            }));
        }
Пример #3
0
        private BsonValue TranslateSelect(SelectExpression node)
        {
            if (node.Source is IFieldExpression && node.Selector is IFieldExpression)
            {
                var prefixName = ((IFieldExpression)node.Source).FieldName;
                return(TranslateValue(FieldNamePrefixer.Prefix(node.Selector, prefixName)));
            }

            var inputValue = TranslateValue(node.Source);
            var inValue    = TranslateValue(FieldNamePrefixer.Prefix(node.Selector, "$" + node.ItemName));

            return(new BsonDocument("$map", new BsonDocument
            {
                { "input", inputValue },
                { "as", node.ItemName },
                { "in", inValue }
            }));
        }
Пример #4
0
        private BsonValue TranslateSelect(SelectExpression node)
        {
            var inputValue = TranslateValue(node.Source);
            var inValue    = TranslateValue(FieldNamePrefixer.Prefix(node.Selector, "$" + node.ItemName));

            if (inputValue.BsonType == BsonType.String && inValue.BsonType == BsonType.String)
            {
                // if inputValue is a BsonString and inValue is a BsonString,
                // then it is a simple field inclusion...
                // inValue is prefixed with a $${node.ItemName}, so we remove the itemName and the 2 $s.
                return(inputValue.ToString() + inValue.ToString().Substring(node.ItemName.Length + 2));
            }

            return(new BsonDocument("$map", new BsonDocument
            {
                { "input", inputValue },
                { "as", node.ItemName },
                { "in", inValue }
            }));
        }
Пример #5
0
        public static Expression Prefix(Expression node, string prefix)
        {
            var replacer = new FieldNamePrefixer(prefix);

            return(replacer.Visit(node));
        }
Пример #6
0
 public static Expression Prefix(Expression node, string prefix)
 {
     var replacer = new FieldNamePrefixer(prefix);
     return replacer.Visit(node);
 }