Esempio n. 1
0
        public IDataAdapter Aggregate(object pipeline, out string result)
        {
            AggregatePipelineModel model   = (AggregatePipelineModel)pipeline;
            BsonDocument           Match   = BsonDocument.Parse(model.Match);
            BsonDocument           Sort    = BsonDocument.Parse(model.Sort);
            BsonDocument           Group   = BsonDocument.Parse(model.Group);
            BsonDocument           Project = BsonDocument.Parse(model.Project);

            if (model.Lookup == null)
            {
                result = _collection.Aggregate()
                         .Match(Match)
                         .Group(Group)
                         .Project(Project)
                         .Sort(Sort)
                         .ToList().ToJson();
            }
            else
            {
                result = _collection.Aggregate()
                         .Match(Match)
                         .Group(Group)
                         .Project(Project)
                         .Lookup(model.Lookup.ForeignCollectionName,
                                 model.Lookup.LocalFieldName,
                                 model.Lookup.ForeignFieldName,
                                 model.Lookup.ResultAs)
                         .Sort(Sort)
                         .ToList().ToJson();
            }

            return(this);
        }
Esempio n. 2
0
        public Result GetAvailableSeats(string concertId, IMessage msg)
        {
            AggregatePipelineModel model = new AggregatePipelineModel();

            model.Match   = "{'concertId':'{0}', 'bookingStatus._id': 'bs01'}".Replace("{0}", concertId);
            model.Group   = "{ '_id':  {'zoneId':'$zone._id', 'zone': '$zone.zone', 'price': '$zone.price'}, 'totalAvailable':{ '$sum': 1 } }";
            model.Project = @"{
                    '_id': 0,
                     'zoneId': '$_id.zoneId',
                    'zone': '$_id.zone',
                    'price': '$_id.price',
                    'totalAvailable': '$totalAvailable'
                    }";
            model.Sort    = "{'price':-1}";
            model.Lookup  = new LookupModel {
                ForeignCollectionName = "concertTicketZones",
                LocalFieldName        = "zoneId",
                ForeignFieldName      = "_id",
                ResultAs = "totalTickets"
            };


            return(this.BizObject.Execute(
                       this.DbConfig,
                       BusinessOperator.Aggregate,
                       model,
                       msg
                       ));
        }