Ejemplo n.º 1
0
        /// <summary>
        /// 通过Aggregate统计查询
        /// </summary>
        public List <R> Aggregate <R>(PipelineDefinition <T, R> pipeline)
        {
            var cursor = MongoCollection.AggregateAsync(pipeline).Result;
            var result = cursor.ToList();

            return(result);
        }
Ejemplo n.º 2
0
        public async Task <IEnumerable <TDocument> > Aggregate(IWorkContext context, PipelineDefinition <TDocument, TDocument> pipeline, AggregateOptions options = null)
        {
            Verify.IsNotNull(nameof(context), context);

            using (var cursor = await MongoCollection.AggregateAsync(pipeline, options, context.CancellationToken))
            {
                return(await cursor.ToListAsync(context.CancellationToken));
            }
        }
Ejemplo n.º 3
0
        public async Task <int> GetHighestTagNumberAsync()
        {
            var result = await MongoCollection
                         .AggregateAsync(
                PipelineDefinition <Resident, BsonDocument> .Create(
                    new BsonDocument("$unwind", "$tags"),
                    new BsonDocument(
                        "$group", new BsonDocument
            {
                { "_id", "$_id" },
                { "max", new BsonDocument("$max", "$tags") }
            }),
                    new BsonDocument("$sort", new BsonDocument("max", -1)),
                    new BsonDocument("$limit", 1)));

            return(result.Single()["max"].AsInt32);
        }