/// <summary>
        ///
        /// </summary>
        /// <param name="name">The name of the field</param>
        /// <param name="stage">The stage that you're processing</param>
        /// <param name="sbProjections">A buffer of projections to append to</param>
        /// <param name="sbGroups">A buffer of group fields to append to</param>
        /// <param name="stageJson">The name wrapped json of a stage</param>
        private static void GenerateStageAggregateCode(string name, AggregateStage stage, StringBuilder sbProjections,
                                                       StringBuilder sbGroups, string stageJson)
        {
            switch (stage.Type)
            {
            case AggregateStageType.Group:
                //TODO: provide group name
                var stageWrap = stage.WrapValueWithRoot(name);
                var gBsonDoc  = $"groupFields.Merge(BsonDocument.Parse({stageWrap}));";
                //Append our group to the projections so that it's visible
                var pBsonDocFake = $"projections.Merge(new BsonDocument" + "{{\"" + name + "\", \"$" +
                                   name + "\"}}" + ");";
                sbProjections.AppendLine(pBsonDocFake);
                sbGroups.AppendLine(gBsonDoc);
                break;

            case AggregateStageType.Project:
                var pBsonDoc = $"projections.Merge(BsonDocument.Parse({stageJson}));";
                sbProjections.AppendLine(pBsonDoc);
                break;

            default:
                throw new NotImplementedException("Support for root pipeline expression not implemented: " +
                                                  stage.Type.ToString());
            }
        }
Esempio n. 2
0
        public AggregateStage AddProjection(IDonutFunction function)
        {
            var stage = new AggregateStage(_script, function);

            Stages.Add(stage);
            return(stage);
        }
Esempio n. 3
0
        public AggregateStage Clone()
        {
            var nstage = new AggregateStage(_script, Function);

            nstage.Type        = Type;
            nstage.ChildStages = new List <AggregateStage>(ChildStages.ToArray());
            return(nstage);
        }