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


C# MongoCollection.FindOneById方法代码示例

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


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

示例1: Upsert

 protected bool Upsert(MongoCollection<object> collection, object obj, Guid id)
 {
     if (collection.FindOneById(id) != null)
         return collection.Update(Query.EQ("_id", id), Update.Replace(obj), WriteConcern.Acknowledged).Ok;
     else
         return Add(collection, obj);
 }
开发者ID:pitlabcloud,项目名称:activity-cloud,代码行数:7,代码来源:BaseRegistry.cs

示例2: BuildPOI

        public static poi BuildPOI(MongoCollection<category> categories, poi poi, bool minimal)
        {
            if (poi != null)
            {
                if (poi.categoryIDs != null && poi.categoryIDs.Count > 0)
                {
                    poi.category = new List<category>();

                    foreach (var catID in poi.categoryIDs)
                    {
                        var cat = categories.FindOneById(catID);

                        if (cat.deleted != null && cat.deleted <= DateTime.UtcNow)
                            continue;

                        foreach (var l in cat.label)
                        {
                            poi.category.Add(new category
                                {
                                    lang = l.lang,
                                    value = l.value,
                                    term = "category"
                                });

                            if (cat.link != null)
                            {
                              if (poi.link == null)
                                poi.link = new List<POITermType>();

                              foreach (var link in cat.link)
                              {
                                if (link.term == "icon")
                                {
                                  poi.link.Add(link);
                                }
                              }
                            }
                        }

                    }
                }

                if (minimal)
                {
                    if (poi.location != null)
                    {
                        poi.location.address = null;
                        poi.location.relationship = null;
                    }

                    if (poi.link != null)
                        poi.link.RemoveAll(r => r.term != "icon");
                }
            }

            return poi;
        }
开发者ID:CitySDK,项目名称:tourism_api_reference_server,代码行数:57,代码来源:POIService.cs

示例3: AddEvent

 private void AddEvent(ObjectId id, int statusCode, MongoCollection<Entity> collection)
 {
     var entity = collection.FindOneById(id);
     entity.StatusCode = statusCode;
     entity.Events.Add(new EntityEvent
     {
         CreatedAt = DateTime.Now,
         Description = Guid.NewGuid().ToString(),
         StatusCode = statusCode
     });
     collection.Save(entity);
 }
开发者ID:qwert789,项目名称:codegallery,代码行数:12,代码来源:ReuseEntityRepositoryTests.cs

示例4: ReadItemsById

 private static TestResult ReadItemsById(MongoCollection<Person> collection, int readCount, List<string> ids)
 {
     var time = Stopwatch.StartNew();
     foreach (var id in ids)
     {
         var person = collection.FindOneById(id);
         if (person == null)
             throw new ArgumentException("Id doesn't exist.");
         //Console.WriteLine(person.LastName);
     }
     time.Stop();
     var result = new TestResult { Count = readCount, TotalMs = time.ElapsedMilliseconds };
     Console.WriteLine("Reading total time: {0} ms avg: {1} ms for #records: {2}", result.TotalMs,
                       result.ItemAvgMs, ids.Count);
     return result;
 }
开发者ID:pvasek,项目名称:RavenVsMongo,代码行数:16,代码来源:MongoTest.cs

示例5: GenerateRoles

        /// <summary>
        /// Generates the roles.
        /// </summary>
        /// <param name="minRolesNumber">The min roles number.</param>
        /// <param name="maxRolesNumber">The max roles number.</param>
        /// <param name="actorIds">The actor ids.</param>
        /// <param name="actors">The actors.</param>
        /// <returns>Roles collection</returns>
        private ICollection<Role> GenerateRoles( int minRolesNumber, int maxRolesNumber, ICollection<ActorId> actorIds, MongoCollection<Actor> actors )
        {
            var random = new Random();
            int roleRecordsNumber = random.Next( maxRolesNumber - minRolesNumber + 1 ) + minRolesNumber;
            if (actorIds.Count < roleRecordsNumber) roleRecordsNumber = actorIds.Count;

            var randomActorIds = GetRandomActorIds( actorIds, roleRecordsNumber );

            var roles = new List<Role>( roleRecordsNumber );
            for (int i = 0; i < roleRecordsNumber; i++)
            {
                var nActorId = random.Next( randomActorIds.Count );
                var actor = actors.FindOneById( randomActorIds[nActorId].Id );
                var role = new Role
                               {
                                   Actor = new ActorShortDetail( actor ),
                                   RoleName = string.Format( DefaultRoleNameFormat, i ),
                               };
                roles.Add( role );

                randomActorIds.RemoveAt( nActorId );
            }
            return roles;
        }
开发者ID:YRazvalinov,项目名称:MovieCatalog,代码行数:32,代码来源:MongoRepository.cs

示例6: FillSubCategories

        private void FillSubCategories(MongoCollection<category> database, int depth, category cat)
        {
            // Sanity check of recursiveness check
              if (depth >= MAX_DEPTH)
            return;

              if(cat.categories == null)
              {
            cat.categories = new System.Collections.Generic.List<ServiceModel.Types.category>();
            if(!cat.categoryIDs.IsNullOrEmpty())
            {
              foreach(ObjectId subCatId in cat.categoryIDs)
              {
                category subCat = database.FindOneById(subCatId);

                if(subCat != null)
                  FillSubCategories(database, depth + 1, subCat);

                cat.categories.Add(subCat);
              }
            }
              }
        }
开发者ID:CitySDK,项目名称:tourism_api_reference_server,代码行数:23,代码来源:CategoryService.cs

示例7: BuildRoute

        public static route BuildRoute(MongoCollection<category> categories, MongoCollection<poi> pois, route r, bool includePois)
        {
            if (r != null)
            {
                if (r.categoryIDs != null && r.categoryIDs.Count > 0)
                {
                    r.category = new List<category>();

                    foreach (var catID in r.categoryIDs)
                    {
                      var cat = categories.FindOneById(catID);

                      if (cat.deleted <= DateTime.Now)
                        continue;

                      foreach (var l in cat.label)
                      {
                        r.category.Add(new category()
                        {
                          term = "category",
                          value = l.value,
                          lang = l.lang
                        });
                      }

                      if (cat.link != null)
                      {
                        if (r.link == null)
                          r.link = new List<POITermType>();

                        foreach (var link in cat.link)
                        {
                          if (link.term == "icon")
                            r.link.Add(link);

                        }
                      }

                    }
                }

                if (!includePois)
                {
                  r.pois = null;
                }
                else
                {
                  foreach (var p in r.pois)
                  {
                    if (p.location != null && !p.location.relationship.IsNullOrEmpty())
                    {
                      var parentPOIR = p.location.relationship.FirstOrDefault(w => w.term == "equals");

                      if (parentPOIR != null && parentPOIR.targetPOI != ObjectId.Empty)
                      {
                        var pPoi = pois.FindOneById(parentPOIR.targetPOI);

                        if (pPoi != null && pPoi.location != null)
                        {
                          if (pPoi.location.point != null)
                          {
                            p.location.point = pPoi.location.point;
                          }
                          else if (pPoi.location.line != null)
                          {
                            p.location.line = pPoi.location.line;
                          }
                          else if (pPoi.location.polygon != null)
                          {
                            p.location.polygon = pPoi.location.polygon;
                          }
                        }
                      }
                    }
                  }
                }
            }

            return r;
        }
开发者ID:CitySDK,项目名称:tourism_api_reference_server,代码行数:80,代码来源:RouteService.cs

示例8: BuildEvent

        public static @event BuildEvent(MongoCollection<category> categories, MongoCollection<poi> pois, @event ev)
        {
            if (ev != null)
            {
                if (ev.deleted < DateTime.UtcNow)
                    return null;

                if (ev.categoryIDs != null && ev.categoryIDs.Count > 0)
                {
                    ev.category = new List<category>();

                    foreach (var catID in ev.categoryIDs)
                    {
                      var cat = categories.FindOneById(catID);

                      if (cat.deleted <= DateTime.Now)
                        continue;

                      foreach (var l in cat.label)
                      {
                        ev.category.Add(new category()
                          {
                            lang = l.lang,
                            value = l.value,
                            term = "category"
                          }
                        );

                        if (cat.link != null)
                        {
                          if (ev.link == null)
                            ev.link = new List<POITermType>();

                          foreach (var link in cat.link)
                          {
                            if (link.term == "icon")
                              ev.link.Add(link);
                          }
                        }
                      }
                    }
                }

                // Fill the coordinates
                if (ev.location.relationship != null && ev.location.relationship.Count > 0)
                {
                  List<location> poiLocations = new List<location>();

                  // Find related pois
                  foreach (var relation in ev.location.relationship)
                  {
                    if (relation.targetPOI == null)
                      continue;

                    poi eventPoi = pois.FindOneById(relation.targetPOI);
                    if (eventPoi == null)
                      continue;

                    // Store related pois locations
                    poiLocations.Add(eventPoi.location);
                  }

                  // Add coordinates to the event
                  foreach (location loc in poiLocations)
                  {
                    if (loc.line != null && loc.line.Count > 0)
                    {
                      if (ev.location.line == null)
                        ev.location.line = loc.line;
                      else
                        ev.location.line.AddRange(loc.line);
                    }

                    if (loc.point != null && loc.point.Count > 0)
                    {
                      if (ev.location.point == null)
                        ev.location.point = loc.point;
                      else
                        ev.location.point.AddRange(loc.point);
                    }

                    if (loc.polygon != null && loc.polygon.Count > 0)
                    {
                      if (ev.location.polygon == null)
                        ev.location.polygon = loc.polygon;
                      else
                        ev.location.polygon.AddRange(loc.polygon);
                    }
                  }
                }
            }

            return ev;
        }
开发者ID:CitySDK,项目名称:tourism_api_reference_server,代码行数:94,代码来源:EventService.cs


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