When utilizing dynamic linq with fluent mongo, grouping by multiple values results in a faulty map-reduce emit statement.

dynamic-linq fluent-mongo mongodb mongodb-.net-driver

Question

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?

1
1
3/14/2012 9:10:28 PM

Popular Answer

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

0
10/24/2012 7:32:57 AM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow