私はC#で比較的些細なMongoDBMapReduceデモに取り組んでいます。
コードは次のとおりです。
public List<CategorySummaryResult> GetCategorySummaries()
{
string map = @"
function() {
var key = this.FeedType;
var value = {count: 1, names: this.Name};
emit(key, value);
}";
string reduce = @"
function(key, values) {
var result = {count: 0, names: ''};
values.forEach(function(value) {
result.count += value.count;
result.names += ',' + value.names;
});
return result;
}";
string finalize = @"
function(key, value) {
if (value.names.charAt(0) === ',')
value.names = value.names.substr(1);
return value;
}";
var options =
MapReduceOptions
.SetFinalize(finalize)
.SetOutput(MapReduceOutput.Inline);
var result =
_db.GetCollection("NewsCategories")
.MapReduce(map, reduce, options)
.GetInlineResultsAs<CategorySummaryResult>()
.ToList();
return result;
}
デシリアライズするオブジェクト:
public class CategorySummaryResult
{
public double id { get; set; }
public ICollection<CategorySummary> value { get; set; }
}
public class CategorySummary
{
public double count { get; set; }
public string names { get; set; }
}
BSON出力は次のようになります。
[0]: { "_id" : 1.0, "value" : { "count" : 3.0, "names" : "Games,Technologie,Auto" } }
[1]: { "_id" : 2.0, "value" : { "count" : 1.0, "names" : "Hoofdpunten" } }
ただし、次の例外が発生し続けます。
An error occurred while deserializing the value property of class MetroNews.Managers.CategorySummaryResult:
Expected element name to be '_t', not 'count'.
何が問題になっていて、どうすれば修正できますか?