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


C# IMongoCollection.FindAsync方法代码示例

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


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

示例1: ExecuteAsync

        public async Task<IEnumerable<Climb>> ExecuteAsync(GetClimbsQueryParameters parameters,
            IMongoCollection<Climb> collection)
        {
            var filters = new List<FilterDefinition<Climb>>();

            if (parameters.Id != Guid.Empty)
            {
                var filter = Builders<Climb>.Filter.Eq(c => c.Id == parameters.Id, true);

                filters.Add(filter);
            }

            if (parameters.Styles != null && parameters.Styles.Count > 0)
            {
                var filter = Builders<Climb>.Filter.AnyIn(c => c.Styles, parameters.Styles);
                filters.Add(filter);
            }

            if (!string.IsNullOrEmpty(parameters.Name))
            {
                var filter = Builders<Climb>.Filter.Eq(c => c.Name == parameters.Name, true);
                filters.Add(filter);
            }

            var complexFilter = Builders<Climb>.Filter.And(filters);

            var fullCollection = await collection.FindAsync(complexFilter);
            return await fullCollection.ToListAsync();
        }
开发者ID:MikeBeastall,项目名称:MonkeyStrong,代码行数:29,代码来源:GetClimbsQuery.cs

示例2: Dr

        private static async Task Dr(IMongoCollection<BsonDocument> leaders, BsonDocument filter, IMongoCollection<BsonDocument> users, IMongoCollection<BsonDocument> leadersbak)
        {
            using (var cursor = await leaders.FindAsync(filter))
            {

                while (await cursor.MoveNextAsync())
                {
                    var batch = cursor.Current;
                    foreach (var rt in batch)
                    {
                        BsonArray bRetweeters = rt["retweeters_id"].AsBsonArray;

                        //if (bRetweeters.Count == 0)
                        //    continue;

                        foreach (var bUser in bRetweeters)
                        {
                            var lUser = bUser.ToInt64();
                            try
                            {

                                log.Info("readling retweeter {0}", lUser);
                                var usersFilter = Builders<BsonDocument>.Filter.Eq("id", lUser);
                                var result = await users.Find(usersFilter).ToListAsync();
                                if (result.Count > 0)
                                    continue;

                                log.Info("downloading retweeter {0}", lUser);
                                TwitterProfileHandler profileHandler = new TwitterProfileHandlerMongo();
                                string screenName = profileHandler.Download(lUser);
                                //TwitterHomelineHandler homeHandler = new TwitterHomelineHandlerMongo();
                                //homeHandler.Download(screenName);
                            }
                            catch (Exception ex)
                            {
                                string msg = "Error trying to download profile for user:{0}";
                                msg = string.Format(msg, lUser);
                                log.Error(ex, msg);
                            }
                        }

                        //rt["done"] = true;
                        //var filterupdate = Builders<BsonDocument>.Filter.Eq("_id", rt["_id"]);
                        //var update = Builders<BsonDocument>.Update.Push("done", true);
                        //await leaders.UpdateOneAsync(filterupdate, rt);
                        await leadersbak.InsertOneAsync(rt);
                        var filterbak = Builders<BsonDocument>.Filter.Eq("_id", rt["_id"]);
                        await leaders.DeleteOneAsync(filterbak);
                    }
                }
            }

            Thread.Sleep(5000);
        }
开发者ID:johnnytorres,项目名称:twitterlc,代码行数:54,代码来源:Program.cs

示例3: Execute

 protected override void Execute(IMongoCollection<BsonDocument> collection, bool async)
 {
     if (async)
     {
         var cursor = collection.FindAsync(_filter, _options).GetAwaiter().GetResult();
         cursor.ToListAsync().GetAwaiter().GetResult();
     }
     else
     {
         collection.FindSync(_filter, _options).ToList();
     }
 }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:12,代码来源:FindTest.cs

示例4: ExecuteAsync

 protected override Task ExecuteAsync(IMongoCollection<BsonDocument> collection)
 {
     var cursor = collection.FindAsync(_filter, _options).GetAwaiter().GetResult();
     return cursor.ToListAsync();
 }
开发者ID:RainsSoft,项目名称:mongo-csharp-driver,代码行数:5,代码来源:FindTest.cs


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