Attempting to include a query in a MongoDB MapReduce call

I am trying to create a very simple example of map reduction, which also includes a request in the api call of MapReduce.

My collection has many entries formatted as follows:

{ "_id" : { "$binary" : "PdYV4WMTAEyYMQHXJZfzvA==", "$type" : "03" }, 
    "firstname" : "Matthew", 
    "surname" : "Chambers", 
    "email" : "" }

The code is as follows:

var map = @"
function() {
    emit(this.surname, { count : 22 });
}";
var reduce = @"
function(key, emitValues) {
    return { count : emitValues[0].count };
}";

List<BsonValue> contactIds = new List<BsonValue>();
contactIds.Add(new Guid("A04FC88D-7BF7-443D-B5C3-EB11EE2B36DF"));
contactIds.Add(new Guid("26B690B3-5ED7-47F4-A878-3906E28BBC58"));
MongoDB.Driver.Builders.QueryConditionList queryList = MongoDB.Driver.Builders.Query.In("_id", BsonArray.Create(contactIds));
//var mr = personCollection.MapReduce(map, reduce);// THIS WORKS!    
var mr = personCollection.MapReduce(queryList, map, reduce); // THIS FAILS

Everything works if I do not include queryList in the MapReduce call. However, if I turn on queryList, I get the following runtime error:

'mapreduce' failed: db assertion failure (response: { "assertion": "out" "," assertionCode ": 13606," errmsg ":" db assertion failure "" ok": 0})      MongoDB.Driver.MongoDatabase.RunCommandAs [TCommandResult] ( IMongoCommand) C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoDatabase.cs: 621 MongoDB.Driver.MongoCollection.MapReduce( BsonJavaScript, BsonJavaScript , IMongoMapReduceOptions) C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs: 788 MongoDB.Driver.MongoCollection.MapReduce( IMongoQuery, BsonJavaScript, BsonJavaScript ) C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoCollection.cs: 823 HPSLucene.Models.Mongo.MapReduce() C:\Inetpub\wwwroot\HPSLucene\HPSLucene\Models\Mongo.cs: 158

- , ? .

+5
3

, , , ,

. (, , ), (, , ). , arg .

: (, , , ) , , .

. M/R, :

var mr = personCollection.MapReduce(queryList, map, reduce, 
                MapReduceOptions.SetOutput(MapReduceOutput.Inline));
+7

Btw, AdaTheDev, , :

List<BsonValue> contactIds = new List<BsonValue>();
contactIds.Add(new Guid("A04FC88D-7BF7-443D-B5C3-EB11EE2B36DF"));
contactIds.Add(new Guid("26B690B3-5ED7-47F4-A878-3906E28BBC58"));
MongoDB.Driver.Builders.QueryConditionList queryList = MongoDB.Driver.Builders.Query.In("_id", BsonArray.Create(contactIds));
MongoDB.Driver.Builders.MapReduceOptionsBuilder builder=new MongoDB.Driver.Builders.MapReduceOptionsBuilder();
builder.SetOutput(MongoDB.Driver.Builders.MapReduceOutput.Inline);
var mr = personCollection.MapReduce(map, reduce, builder);
+3

I created a test program to reproduce this, and it seems that it actually causes the correct MapReduce overload. But you have encountered a driver error. I created a JIRA case for it:

http://jira.mongodb.org/browse/CSHARP-193

Your final version is fine. By providing an explicit options parameter, you are working on the error.

0
source

All Articles