craiggwilson/fluent-mongo — Issue #53: Malformed emit statement when using dynamic linq and a groupby with multiple values
Author: seanngreen
Created: 2012-03-09 04:00:24+00:00
State: open

I'm using dynamic link to run mapreduce queries and I'm running into a problem when trying to group by multiple values. Check this out:

This works fine:

var query = contentDeliveryAggregates.AsQueryable().Where("_id.CId == 1 && _id.CdaId == 1 && _id.From >= @0 && _id.To <= @1", reportRequest.FromDate, reportRequest.ToDate). GroupBy("_id.CdaId", "it"). Select("new(key,Sum(value.BW) as Bandwidth)");

This does not:

var query = contentDeliveryAggregates.AsQueryable().Where("_id.CId == 1 && _id.CdaId == 1 && _id.From >= @0 && _id.To <= @1", reportRequest.FromDate, reportRequest.ToDate). GroupBy("new(_id.CdaId, _id.CId)", "it"). Select("new(key,Sum(value.BW) as Bandwidth)");

The linq is valid I think (it compiles and runs fine), but I get a runtime error because the mapreduce statement is malformed. Here's the map-reduce statement from the second query:

{ "mapreduce" : "Aggregates", "map" : { "$code" : "function() { emit({}this._id.CdaIdthis.id.CId, {\"$f0\": this.value.BW}); }" }, "reduce" : { "$code" : "function(key, values) {var $f0 = 0;values.forEach(function(doc) {$f0 += doc.$f0;});return { \"$f0\": _$f0};}" }, "query" : { "_id.CId" : 1, "_id.CdaId" : 1, "_id.From" : { "$gte" : ISODate("2012-02-01T08:00:00Z") }, "id.To" : { "$lte" : ISODate("2012-02-11T08:00:00Z") } }, "finalize" : { "$code" : "function(key, value) { return { \"$f0\": value._$f0};}" }, "limit" : 0, "out" : { "inline" : 1 } }

Check out that emit statement; it's messed up...

I belive this is this a bug in the fluent driver...