@@ -342,6 +342,28 @@ describe('e2e', function() {
342
342
shell . assertNoErrors ( ) ;
343
343
} ) ;
344
344
345
+ it ( 'rewrites async properly for mapReduce' , async ( ) => {
346
+ // This is being run under the new async rewriter because the old one
347
+ // did not support mapReduce at all (because of needing 'this').
348
+ // Once the new async rewriter is the default, this block can be removed.
349
+ shell = TestShell . start ( {
350
+ args : [ await testServer . connectionString ( ) ] ,
351
+ env : { ...process . env , MONGOSH_ASYNC_REWRITER2 : '1' }
352
+ } ) ;
353
+ await shell . waitForPrompt ( ) ;
354
+ shell . assertNoErrors ( ) ;
355
+
356
+ await shell . executeLine ( `use ${ dbName } ` ) ;
357
+ await shell . executeLine ( 'db.test.insertMany([{i:1},{i:2},{i:3},{i:4}]);' ) ;
358
+ const result = await shell . executeLine ( `db.test.mapReduce(function() {
359
+ emit(this.i % 2, this.i);
360
+ }, function(key, values) {
361
+ return Array.sum(values);
362
+ }, { out: { inline: 1 } }).results` ) ;
363
+ expect ( result ) . to . include ( '{ _id: 0, value: 6 }' ) ;
364
+ expect ( result ) . to . include ( '{ _id: 1, value: 4 }' ) ;
365
+ } ) ;
366
+
345
367
it ( 'expands explain output indefinitely' , async ( ) => {
346
368
await shell . executeLine ( 'explainOutput = db.test.find().explain()' ) ;
347
369
await shell . executeLine ( 'explainOutput.a = {b:{c:{d:{e:{f:{g:{h:{i:{j:{}}}}}}}}}}' ) ;
0 commit comments