1

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 (it compiles 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...

Am I doing something wrong or is this a bug in the fluent driver?

Sean Green
  • 11
  • 2

1 Answers1

0

From the mongodb linq tutorial http://www.mongodb.org/display/DOCS/CSharp+Driver+LINQ+Tutorial

"Only LINQ queries that can be translated to an equivalent MongoDB query are supported. If you write a LINQ query that can't be translated you will get a runtime exception and the error message will indicate which part of the query wasn't supported."

Unfortunately group by is not in the supported list, hopefully someone will add it soon

Mingo
  • 836
  • 3
  • 12
  • 19