summaryrefslogtreecommitdiff
path: root/jstests/mr_replaceIntoDB.js
diff options
context:
space:
mode:
authoragirbal <antoine@10gen.com>2011-01-05 22:05:10 -0800
committeragirbal <antoine@10gen.com>2011-01-05 22:06:04 -0800
commitda0bc2917778593d0368b89427d9d504a1230389 (patch)
tree471dc196e107b92e6e6bce81c06df7cdd67357db /jstests/mr_replaceIntoDB.js
parentb72cf3543836d108233c684c4e5e45da65ea101c (diff)
downloadmongo-da0bc2917778593d0368b89427d9d504a1230389.tar.gz
[SERVER-1951]: M/R output param should allow us to use db.collection not only collection
Diffstat (limited to 'jstests/mr_replaceIntoDB.js')
-rw-r--r--jstests/mr_replaceIntoDB.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/jstests/mr_replaceIntoDB.js b/jstests/mr_replaceIntoDB.js
new file mode 100644
index 00000000000..81af1c2491b
--- /dev/null
+++ b/jstests/mr_replaceIntoDB.js
@@ -0,0 +1,44 @@
+
+t = db.mr_replace;
+t.drop();
+
+t.insert( { a : [ 1 , 2 ] } )
+t.insert( { a : [ 2 , 3 ] } )
+t.insert( { a : [ 3 , 4 ] } )
+
+outCollStr = "mr_replace_col";
+outDbStr = "mr_db";
+
+m = function(){ for (i=0; i<this.a.length; i++ ) emit( this.a[i] , 1 ); }
+r = function(k,vs){ return Array.sum( vs ); }
+
+function tos( o ){
+ var s = "";
+ for ( var i=0; i<100; i++ ){
+ if ( o[i] )
+ s += i + "_" + o[i];
+ }
+ return s;
+}
+
+print("Testing mr replace into other DB")
+res = t.mapReduce( m , r , { out : { replace: outCollStr, db: outDbStr } } )
+expected = { "1" : 1 , "2" : 2 , "3" : 2 , "4" : 1 };
+outDb = db.getMongo().getDB(outDbStr);
+outColl = outDb[outCollStr];
+str = tos( outColl.convertToSingleObject("value") )
+print("Received result: " + str);
+assert.eq( tos( expected ) , str , "Received wrong result " + str );
+
+print("checking result field");
+assert.eq(res.result.collection, outCollStr, "Wrong collection " + res.result.collection)
+assert.eq(res.result.db, outDbStr, "Wrong db " + res.result.db)
+
+print("Replace again and check");
+outColl.save({_id: "5", value : 1});
+t.mapReduce( m , r , { out : { replace: outCollStr, db: outDbStr } } )
+str = tos( outColl.convertToSingleObject("value") )
+print("Received result: " + str);
+assert.eq( tos( expected ) , str , "Received wrong result " + str );
+
+