本文整理汇总了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();
}
示例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);
}
示例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();
}
}
示例4: ExecuteAsync
protected override Task ExecuteAsync(IMongoCollection<BsonDocument> collection)
{
var cursor = collection.FindAsync(_filter, _options).GetAwaiter().GetResult();
return cursor.ToListAsync();
}