Skip to content
Browse files

Added test coverage for map-reduce errors

  • Loading branch information...
1 parent 8c2d253 commit f7ba66e413e2a92bb44a06ad0c333baac4450fbd @christkv committed Mar 15, 2012
Showing with 33 additions and 16 deletions.
  1. +1 −0 HISTORY
  2. +4 −15 lib/mongodb/collection.js
  3. +28 −1 test/map_reduce_test.js
View
1 HISTORY
@@ -1,3 +1,4 @@
+- stats not returned from map reduce with inline results (Issue #542)
- Re-enable testing of whether or not the callback is called in the multi-chunk seek, fix small GridStore bug (Issue #543, https://github.com/pgebheim)
0.9.9.6 2012-03-12
View
19 lib/mongodb/collection.js
@@ -1025,7 +1025,7 @@ Collection.prototype.reIndex = function(callback) {
* @param {Function|String} map the mapping function.
* @param {Function|String} reduce the reduce function.
* @param {Objects} [options] options for the map reduce job.
- * @param {Function} callback returns the result of the map reduce job.
+ * @param {Function} callback returns the result of the map reduce job, (error, results, [stats])
* @return {null}
* @api public
*/
@@ -1059,28 +1059,17 @@ Collection.prototype.mapReduce = function mapReduce (map, reduce, options, callb
mapCommandHash[name] = options[name];
}
- // console.log("+++++++++++++++++++++++++++++++++++++ mapCommandHash")
- // console.dir(mapCommandHash)
-
var self = this;
var cmd = DbCommand.createDbSlaveOkCommand(this.db, mapCommandHash);
this.db._executeQueryCommand(cmd, {read:true}, function (err, result) {
- // console.log("++++++++++++++++++++++++++++++++++++++++++++++++++++++++ RESULTS")
- // console.dir(err)
- // console.dir(result)
-
if (err) {
return callback(err);
}
- if (1 != result.documents[0].ok) {
- return callback(result.documents[0]);
- }
-
- // If we wish for no verbosity
- if(options['verbose'] == null || !options['verbose']) {
- return callback(err, collection);
+ //
+ if (1 != result.documents[0].ok || result.documents[0].err || result.documents[0].errmsg) {
+ return callback(self.db.wrap(result.documents[0]));
}
// Create statistics value
View
29 test/map_reduce_test.js
@@ -234,7 +234,7 @@ exports.shouldPerformSimpleMapReduceFunctions = function(test) {
}
/**
- * A simple map reduce example using the inline output type on MongoDB > 1.7.6
+ * A simple map reduce example using the inline output type on MongoDB > 1.7.6 returning the statistics
*
* @_class collection
* @_function mapReduce
@@ -360,6 +360,33 @@ exports.shouldPerformMapReduceWithStringFunctions = function(test) {
}
/**
+* Mapreduce tests
+* @ignore
+*/
+exports.shouldForceMapReduceError = function(test) {
+ client.createCollection('test_map_reduce', function(err, collection) {
+ collection.insert([{'user_id':1}, {'user_id':2}], {safe:true}, function(err, r) {
+ // String functions
+ var map = "function() { emiddft(this.user_id, 1); }";
+ var reduce = "function(k,vals) { return 1; }";
+
+ // Parse version of server if available
+ client.admin().serverInfo(function(err, result){
+
+ // Only run if the MongoDB version is higher than 1.7.6
+ if(parseInt((result.version.replace(/\./g, ''))) >= 176) {
+
+ collection.mapReduce(map, reduce, {out: {inline : 1}}, function(err, collection) {
+ test.ok(err != null);
+ test.done();
+ });
+ };
+ });
+ });
+ });
+}
+
+/**
* @ignore
*/
exports.shouldPerformMapReduceWithParametersBeingFunctions = function(test) {

0 comments on commit f7ba66e

Please sign in to comment.
Something went wrong with that request. Please try again.