Details
-
Bug
-
Resolution: Works as Designed
-
Blocker - P1
-
None
-
2.4.4
-
None
Description
MapReduce when run on db with 3.4.5. version does not produce any result. (Both with inline and output collection).
I tried with C# driver 2.4.4:
- on 3.4.5 version the MapReduce does not work
- on 3.0.2 version everything works fine.
Here's a simple snippet to use to reproduce the bug:
// Example of input documents
|
// {
|
// "_id" : ObjectId("59c52b3cb602cb6397c2ec9d"),
|
// "Timestamp" : NumberLong(1505860144116),
|
// "Value" : 14,
|
// "Date" : ISODate("2017-09-19T22:29:04.116Z")
|
// }
|
|
|
public class Program
|
{
|
private const string MapJs = @"function mapF() {
|
const key = this.Date.getFullYear();
|
const valuePerYear = { total: 1};
|
|
|
emit(key, valuePerYear);
|
}; ";
|
|
|
private const string ReduceJS = @"function reduceF(year, values) {
|
let sum = 0;
|
values.forEach(v => {
|
sum += v.total;
|
});
|
return {total: NumberInt(sum)};
|
}";
|
|
|
public static void Main()
|
{
|
string mongoConnectionString = "my-connection-string";
|
MongoUrl mongoUrl = MongoUrl.Create(mongoConnectionString);
|
MongoClient client = new MongoClient(mongoConnectionString);
|
IMongoDatabase db = client.GetDatabase("ny_database_name");
|
IMongoCollection<BsonDocument> collection = db.GetCollection<BsonDocument>("DocInput");
|
BsonJavaScript map = new BsonJavaScript(MapJs);
|
BsonJavaScript reduce = new BsonJavaScript(ReduceJS);
|
FilterDefinitionBuilder<BsonDocument> filterBuilder = new FilterDefinitionBuilder<BsonDocument>();
|
FilterDefinition<BsonDocument> filter = filterBuilder.Empty;
|
MapReduceOptions<BsonDocument, BsonDocument> options = new MapReduceOptions<BsonDocument, BsonDocument>
|
{
|
Filter = filter,
|
MaxTime = TimeSpan.FromMinutes(1),
|
OutputOptions = MapReduceOutputOptions.Reduce("Result", nonAtomic: true),
|
Verbose = true
|
};
|
try
|
{
|
collection.MapReduce(map, reduce, options).ToList();
|
}
|
catch (Exception ex)
|
{
|
Console.WriteLine($"Exception occurred {ex.Message}");
|
}
|
}
|
}
|
Attachments
Issue Links
- is caused by
-
SERVER-31374 If map function string ends in a semicolon mapReduce fails silently returning no results
-
- Closed
-