当前位置: 首页>>代码示例>>C#>>正文


C# QueryDocument.AddRange方法代码示例

本文整理汇总了C#中MongoDB.Driver.QueryDocument.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# QueryDocument.AddRange方法的具体用法?C# QueryDocument.AddRange怎么用?C# QueryDocument.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MongoDB.Driver.QueryDocument的用法示例。


在下文中一共展示了QueryDocument.AddRange方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RemoveSnake

        public void RemoveSnake(string snakeId)
        {
            var query = new QueryDocument();
            query.AddRange(new Dictionary<string, object>
            {
                {"_id", snakeId}
            });

            _snakesCollection.Remove(query);
        }
开发者ID:FoC-,项目名称:SnakeBattle.Net,代码行数:10,代码来源:SnakeStore.cs

示例2: Get


//.........这里部分代码省略.........

                      if(completeRoute != null)
                        routeResponse.routes.Add(completeRoute);
                    }

                  if (pageLimit != -1)
                    routeResponse.routes = routeResponse.routes.Skip(skipResults).Take(pageLimit).ToList();
                  else
                    routeResponse.routes = routeResponse.routes.Skip(skipResults).ToList();

                  return routeResponse;
                }

                base.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return "Invalid relation: " + request.Relation;
            }

            List<IMongoQuery> queries = new List<IMongoQuery>();

            //Category
            if (!request.Category.IsNullOrEmpty())
            {
                List<IMongoQuery> categoriesList = new List<IMongoQuery>();

                foreach (string category in request.Category.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var catsTofind = MongoDb.POICategories.Find(
                      Query.And(
                        Query.EQ("term", "category"),
                        Query.Matches("label.value", new BsonRegularExpression(".*" + category + ".*", "-i")),
                        Query.Or(Query.NotExists("deleted"), Query.GT("deleted", BsonValue.Create(DateTime.UtcNow)))
                      )
                    );
                    categoriesList.AddRange(catsTofind.Select(category1 => Query.Or(new[] { Query.EQ("categoryIDs", category1._id) })));
                }

                if (categoriesList.Count > 0)
                    queries.Add(Query.Or(categoriesList));
                else
                {
                    // If no category was found, we can already reply a empty response...
                    return new POISResponse();
                }
            }

            QueryDocument qDoc = new QueryDocument();

            if (request.Deleted.IsNullOrEmpty())
            {
              queries.Add(Query.Or(Query.NotExists("deleted"), Query.GT("deleted", BsonValue.Create(DateTime.UtcNow))));
            }

            //Tag
            if (!request.Tag.IsNullOrEmpty())
            {
                queries.Add(Query.And(request.Tag.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(tag => Query.Or(new[] { Query.EQ("tags", tag) }))));
            }

            //Relation
            if (!request.Relation.IsNullOrEmpty())
            {
                queries.Add(Query.And(request.Relation.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(rel => Query.Or(new[] { Query.EQ("location.relationship.targetPOI", rel) }))));
            }

            //Minimal
            if (!request.Minimal.IsNullOrEmpty())
开发者ID:CitySDK,项目名称:tourism_api_reference_server,代码行数:67,代码来源:POIService.cs

示例3: DoFindUsers

        /// <summary>
        /// Finds the list of users that match the criteria.
        /// </summary>
        /// <param name="filter">Filters the results to only users that match.</param>
        /// <param name="tablesorterMetadata">The tablesorter metadata.</param>
        /// <returns>
        /// The list of users that match the criteria.
        /// </returns>
        protected override UserList DoFindUsers(UserSearchCriteria filter, TablesorterMetadata tablesorterMetadata = null)
        {
            MongoCollection<BsonDocument> collection = this.database.GetCollection(iApplyDb.UserAccess._COLLECTION_NAME);

            QueryDocument outerQuery = new QueryDocument();
            List<IMongoQuery> orQueries = new List<IMongoQuery>();

            if (filter.OrganisationIds != null && filter.OrganisationIds.Any())
            {
                orQueries.AddRange(filter.OrganisationIds.Select(organisationId => Query.Exists(string.Format("{0}.{1}", iApplyDb.UserAccess.ORGANISATIONS, organisationId))));
            }

            if (filter.IncludeNoOrganisationUsers)
            {
                orQueries.Add(Query.NotExists(iApplyDb.UserAccess.ORGANISATIONS));
                orQueries.Add(Query.EQ(iApplyDb.UserAccess.ORGANISATIONS, new BsonDocument()));
            }

            if (!filter.IncludeServiceUsers)
            {
                outerQuery.AddRange(Query.NE(iApplyDb.UserAccess.ACCOUNT_TYPE, new BsonString(AccountType.Service.ToString())).ToBsonDocument());
            }

            if (filter.RoleIds != null && filter.RoleIds.Any())
            {
                orQueries.AddRange(filter.RoleIds.Select(roleId => Query.Exists(string.Format("{0}.{1}", iApplyDb.UserAccess.ROLES, roleId))));
            }

            IMongoQuery subQuery;
            if (orQueries.Count > 0)
            {
                subQuery = Query.Or(orQueries);
                outerQuery.AddRange(subQuery.ToBsonDocument());
            }

            if (filter.UserIds != null && filter.UserIds.Any())
            {
                BsonArray bsonUserIds = new BsonArray();
                bsonUserIds.AddRange(filter.UserIds.Select(u => new BsonObjectId(new ObjectId(u))));
                subQuery = Query.In(iApplyDb.UserAccess._ID, bsonUserIds);
                outerQuery.AddRange(subQuery.ToBsonDocument());
            }

            if (filter.Usernames != null && filter.Usernames.Any())
            {
                BsonArray bsonUserNames = new BsonArray();
                bsonUserNames.AddRange(filter.Usernames.Select(u => new BsonString(u)));
                subQuery = Query.In(iApplyDb.UserAccess.USERNAME, bsonUserNames);
                outerQuery.AddRange(subQuery.ToBsonDocument());
            }

            if (filter.ExternalIds != null && filter.ExternalIds.Any())
            {
                BsonArray bsonExternalIds = new BsonArray();
                bsonExternalIds.AddRange(filter.ExternalIds.Select(u => new BsonString(u)));
                subQuery = Query.In(iApplyDb.UserAccess.EXTERNAL_ID, bsonExternalIds);
                outerQuery.AddRange(subQuery.ToBsonDocument());
            }

            if (tablesorterMetadata != null && tablesorterMetadata.SearchFilters != null)
            {
                for (int i = 0; i < tablesorterMetadata.SearchFilters.Length; i++)
                {
                    var fieldName = tablesorterMetadata.HeaderList[i];
                    var searchTerm = tablesorterMetadata.SearchFilters[i];

                    if (string.IsNullOrWhiteSpace(fieldName) || string.IsNullOrWhiteSpace(searchTerm))
                    {
                        continue;
                    }

                    subQuery = Query.EQ(fieldName, new BsonRegularExpression(searchTerm.Trim(), "i"));
                    outerQuery.AddRange(subQuery.ToBsonDocument());
                }
            }

            MongoCursor<BsonDocument> documents = collection.Find(outerQuery);
            if (tablesorterMetadata != null)
            {
                tablesorterMetadata.TotalRows = Convert.ToInt32(collection.Count(outerQuery));
                documents.SetSkip(tablesorterMetadata.PageSize * tablesorterMetadata.PageIndex).SetLimit(tablesorterMetadata.PageSize);

                if (tablesorterMetadata.SortOrder != null)
                {
                    SortByBuilder newSortByBuilder = new SortByBuilder();
                    foreach (int[] sortCriteria in tablesorterMetadata.SortOrder)
                    {
                        var columnNum = sortCriteria[0];
                        var sortOrder = sortCriteria[1];
                        if (sortOrder == 1)
                        {
                            newSortByBuilder.Descending(tablesorterMetadata.HeaderList[columnNum]);
//.........这里部分代码省略.........
开发者ID:cgavieta,项目名称:WORKPAC2016-poc,代码行数:101,代码来源:MongoDataAccess.Security.cs

示例4: Get

        public object Get(Routes request)
        {
            if (!request.Id.IsNullOrEmpty())
            {
                var objectID = ObjectId.Parse(request.Id);

                var ev = MongoDb.Routes.FindOneById(objectID);

                return BuildRoute(MongoDb.RouteCategories, MongoDb.POIs, ev, true);
            }

            List<IMongoQuery> queries = new List<IMongoQuery>();

            //Category
            if (!request.Category.IsNullOrEmpty())
            {
                List<IMongoQuery> categoriesList = new List<IMongoQuery>();

                foreach (string category in request.Category.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var catsTofind = MongoDb.RouteCategories.Find(
                      Query.And(
                        Query.EQ("term", "category"),
                        Query.Matches("label.value", BsonRegularExpression.Create(".*" + category + ".*", "-i")),
                        Query.Or(Query.NotExists("deleted"), Query.GT("deleted", BsonValue.Create(DateTime.UtcNow)))
                      )
                    );
                    categoriesList.AddRange(catsTofind.Select(category1 => Query.Or(new[] { Query.EQ("categoryIDs", category1._id) })));
                }

                if (categoriesList.Count > 0)
                    queries.Add(Query.Or(categoriesList));
                else
                {
                    return new RoutesResponse();
                }
            }

            //Tag
            if (!request.Tag.IsNullOrEmpty())
            {
                queries.Add(Query.And(request.Tag.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(tag => Query.Or(new[] { Query.EQ("tags", tag) }))));
            }

            //Search
            if (!request.Name.IsNullOrEmpty())
            {
                queries.Add(Query.And(Query.Matches("label.value", "/.*" + request.Name + ".*/i")));
            }

            QueryDocument qDoc = new QueryDocument();

            queries.Add(Query.Or(Query.NotExists("deleted"), Query.GT("deleted", BsonValue.Create(DateTime.UtcNow))));
            qDoc.Add(Query.And(queries).ToBsonDocument());

            MongoCursor<route> routes = MongoDb.Routes.Find(qDoc);

            List<route> FinalRoutes = routes.ToList();

            if (!string.IsNullOrEmpty(request.Coords))
            {
                FinalRoutes = new List<route>();

                foreach (var route in routes)
                {

                    List<IMongoQuery> qs = new List<IMongoQuery>();
                    foreach (var p in route.pois)
                    {
                        if (p.location != null && p.location.relationship != null && p.location.relationship.Count > 0)
                        {
                            var rel = p.location.relationship.AsQueryable().FirstOrDefault(w => w.term == "equals");
                            if (rel != null)
                            {
                                qs.Add(Query.EQ("_id", rel.targetPOI));
                            }
                        }
                    }

                    QueryDocument q1 = new QueryDocument();
                    q1.AddRange(Utilities.GetGeoIntersect(request.Coords).ToBsonDocument());
                    q1.AddRange(Query.Or(qs).ToBsonDocument());

                    if (MongoDb.POIs.Find(q1).Any())
                    {
                        FinalRoutes.Add(route);
                    }
                }
            }

            /*
            if (!request.Show.IsNullOrEmpty())
            {
                int start = int.Parse(request.Show.SplitOnFirst(',')[0]);
                int end = int.Parse(request.Show.SplitOnFirst(',')[1]);

                FinalRoutes = FinalRoutes.Skip(start).Take(end - start).ToList();
            }
            */

//.........这里部分代码省略.........
开发者ID:CitySDK,项目名称:tourism_api_reference_server,代码行数:101,代码来源:RouteService.cs

示例5: Get

        public object Get(Events request)
        {
            if (!request.Id.IsNullOrEmpty())
            {
                var objectID = ObjectId.Parse(request.Id);

                var ev = MongoDb.Events.FindOneById(objectID);

                return BuildEvent(MongoDb.EventCategories, MongoDb.POIs, ev);
            }

            List<IMongoQuery> queries = new List<IMongoQuery>();

            //Category
            if (!request.Category.IsNullOrEmpty())
            {
                List<IMongoQuery> categoriesList = new List<IMongoQuery>();

                foreach (string category in request.Category.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var catsTofind = MongoDb.EventCategories.Find(
                      Query.And(
                        Query.EQ("term", "category"),
                        Query.Matches("label.value", new BsonRegularExpression(".*" + category + ".*", "-i")),
                        Query.Or(Query.NotExists("deleted"), Query.GT("deleted", BsonValue.Create(DateTime.UtcNow)))
                      )
                    );
                    categoriesList.AddRange(catsTofind.Select(category1 => Query.Or(new[] { Query.EQ("categoryIDs", category1._id) })));
                }

                if (categoriesList.Count > 0)
                    queries.Add(Query.Or(categoriesList));
                else
                {
                    return new EventsResponse();
                }
            }

            //Tag
            if (!request.Tag.IsNullOrEmpty())
            {
                queries.Add(Query.And(request.Tag.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(tag => Query.Or(new[] { Query.EQ("tags", tag) }))));
            }

            //Search
            if (!request.Name.IsNullOrEmpty())
            {
                queries.Add(Query.And(Query.Matches("label.value", "/.*" + request.Name + ".*/i")));
            }

            //Time
            if (!request.Time.IsNullOrEmpty())
            {
                string[] dates = request.Time.Split(' ');

                if (dates.Length == 2)
                {
                    DateTime start = DateTime.Parse(dates[0], null, DateTimeStyles.RoundtripKind);
                    DateTime end = DateTime.Parse(dates[1], null, DateTimeStyles.RoundtripKind);

                    //queries.Add(Query.And(Query.GTE("Start", start), Query.LTE("End", end)));
                    queries.Add(Query.And(Query.GTE("End", start), Query.LTE("Start", end)));
                }
            }

            QueryDocument qDoc = new QueryDocument();

            queries.Add(Query.Or(Query.NotExists("deleted"), Query.GT("deleted", BsonValue.Create(DateTime.UtcNow))));
            qDoc.AddRange(Query.And(queries).ToBsonDocument());

            MongoCursor<@event> events = MongoDb.Events.Find(qDoc);

            List<@event> finalEvents = events.ToList();

            if (!string.IsNullOrEmpty(request.Coords))
            {
                finalEvents = new List<@event>();

                var validPois = MongoDb.POIs.Find(Utilities.GetGeoIntersect(request.Coords)).ToList();

                foreach (var ev in events.Where(e => e.location != null && e.location.relationship != null && e.location.relationship.Any()))
                {
                    var rel = ev.location.relationship.AsQueryable().FirstOrDefault(w => w.term == "within" || w.term == "equals");
                    if (rel != null)
                    {
                        if (validPois.Any(a => a._id == rel.targetPOI))
                        {
                            finalEvents.Add(ev);
                        }
                    }
                }
            }

            /*
            if (!request.Show.IsNullOrEmpty())
            {
                int start = int.Parse(request.Show.SplitOnFirst(',')[0]);
                int end = int.Parse(request.Show.SplitOnFirst(',')[1]);

                finalEvents = finalEvents.Skip(start).Take(end - start).ToList();
//.........这里部分代码省略.........
开发者ID:CitySDK,项目名称:tourism_api_reference_server,代码行数:101,代码来源:EventService.cs

示例6: GeoQuery

        public static IMongoQuery GeoQuery(MongoLocation loc, double prox, IMongoQuery query)
        {
            var locQuery = QueryConstants.GeoQuery(loc, prox);

            var q = new QueryDocument();
            q.AddRange(BsonDocument.Parse(locQuery.ToString()));
            if (query != null) q.AddRange(BsonDocument.Parse(query.ToString()));

            return q;
        }
开发者ID:jsouthron,项目名称:nosql,代码行数:10,代码来源:QueryConstants.cs

示例7: get_query_from_str

 public static QueryDocument get_query_from_str(string str)
 {
     BsonDocument doc = BsonSerializer.Deserialize<BsonDocument>(str);
     QueryDocument doc_query = new QueryDocument();
     doc_query.AddRange(doc.Elements);
     return doc_query;
 }
开发者ID:topomondher,项目名称:web_helper,代码行数:7,代码来源:MongoHelper.cs


注:本文中的MongoDB.Driver.QueryDocument.AddRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。