本文整理汇总了C#中MongoCollection.MapReduce方法的典型用法代码示例。如果您正苦于以下问题:C# MongoCollection.MapReduce方法的具体用法?C# MongoCollection.MapReduce怎么用?C# MongoCollection.MapReduce使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoCollection
的用法示例。
在下文中一共展示了MongoCollection.MapReduce方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MapReduceToDocumentid
public async Task<int> MapReduceToDocumentid(MongoCollection collection)
{
string map = @"
function() {
var auditItem = this;
emit(auditItem.DocumentId, { count: 1 });
}";
string reduce = @"
function(key, values) {
var result = {count: 0, Key:key };
values.forEach(function(value){
result.count += value.count;
});
return result;
}";
int count = 0;
try
{
var options = new MapReduceOptionsBuilder();
//options.SetFinalize(finalize);
options.SetOutput(MapReduceOutput.Inline);
var results = collection.MapReduce(map, reduce, options);
var l = new Dictionary<Guid, MapReduceResult>();
foreach (var result in results.GetResults())
{
BsonValue rVal = result["value"];
MapReduceResult d = BsonSerializer.Deserialize<MapReduceResult>(rVal.ToJson());
if (await KeyExists(d.Key))
{
log.InfoFormat("Map reduce duplicate for document id {0} ", d.Key);
continue;
}
count++;
Console.WriteLine("Adding No [{0}] Key {1} ", count, d.Key.ToString());
l.Add(d.Key, d);
var o = await AddToLocalDB(d);
if (count % 100 == 0)
{
log.InfoFormat("{0} document keys processed", count);
}
}
}
catch (Exception ex)
{
log.Error(ex);
}
log.InfoFormat("{0} document keys saved to local cache ");
return count;
}
示例2: MapReduce
public MapReduceResult MapReduce(MongoCollection collection, MapReduceOptionsBuilder options, string name, IFileReader fileReader)
{
options.SetFinalize(ReadFinalizeFile(name, fileReader));
return collection.MapReduce(ReadMapFile(name, fileReader), ReadReduceFile(name, fileReader), options);
}