Пример #1
0
        public async Task <IResultList <Media> > QueryAsync(string appId, MediaQuery query, CancellationToken ct)
        {
            var filters = new List <FilterDefinition <MongoDbMedia> >
            {
                Filter.Eq(x => x.Doc.AppId, appId)
            };

            if (!string.IsNullOrWhiteSpace(query.Query))
            {
                var regex = new BsonRegularExpression(query.Query, "i");

                filters.Add(Filter.Regex(x => x.Doc.FileName, regex));
            }

            var filter = Filter.And(filters);

            var resultItems = await Collection.Find(filter).ToListAsync(query, ct);

            var resultTotal = (long)resultItems.Count;

            if (query.ShouldQueryTotal(resultItems))
            {
                resultTotal = await Collection.Find(filter).CountDocumentsAsync(ct);
            }

            return(ResultList.Create(resultTotal, resultItems.Select(x => x.ToMedia())));
        }
Пример #2
0
        public async Task <IResultList <Media> > QueryAsync(string appId, MediaQuery query,
                                                            CancellationToken ct = default)
        {
            using (Telemetry.Activities.StartActivity("MongoDbMediaRepository/QueryAsync"))
            {
                var filter = BuildFilter(appId, query);

                var resultItems = await Collection.Find(filter).ToListAsync(query, ct);

                var resultTotal = (long)resultItems.Count;

                if (query.ShouldQueryTotal(resultItems))
                {
                    resultTotal = await Collection.Find(filter).CountDocumentsAsync(ct);
                }

                return(ResultList.Create(resultTotal, resultItems.Select(x => x.ToMedia())));
            }
        }