ISSUE DESCRIPTION AND IMPACT
SERVER-28323 added strict checks on conversions between Javascript strings and functions. After upgrading to MongoDB 3.4.6, 3.2.14, or 3.2.15 users may encounter the following error message when using mapReduce:
2017-07-10T16:53:32.121-0400 E QUERY [thread1] Error: map reduce failed:{ "ok" : 0, "errmsg" : "SyntaxError: missing ) in parenthetical @:1:118\n", "code" : 139, "codeName" : "JSInterpreterFailure" } :
AFFECTED VERSIONS
MongoDB 3.2.14, 3.2.15, and 3.4.6.
ISSUE STATUS
This ticket tracks work to relax some of these constraints in future versions of MongoDB and provide a more user-friendly error message.
DIAGNOSIS AND WORKAROUNDS
Users encountering this error should examine the inputs to the mapReduce command and ensure they are functions.
As an example, consider the following mapReduce command, which runs on 3.4.5:
> var mapFunction1 = "function() {emit(this.cust_id, this.price);};" > var reduceFunction1 = "function(keyCustId, valuesPrices) {return Array.sum(valuesPrices);};" > db.orders.insert({ cust_id: "abc123", ord_date: new Date("Oct 04, 2012"), status: 'A', price: 25, items: [ { sku: "mmm", qty: 5, price: 2.5 }, { sku: "nnn", qty: 5, price: 2.5 } ] }) WriteResult({ "nInserted" : 1 }) > db.orders.mapReduce(mapFunction1, reduceFunction1, { out: "map_reduce_example" }) { "result" : "map_reduce_example", "timeMillis" : 226, "counts" : { "input" : 2, "emit" : 2, "reduce" : 1, "output" : 1 }, "ok" : 1 }
Running the same map-reduce command against 3.4.6 results in:
> db.orders.mapReduce(mapFunction1, reduceFunction1, { out: "map_reduce_example" }) 2017-07-10T16:53:31.933-0400 I NETWORK [thread1] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed 2017-07-10T16:53:31.934-0400 I NETWORK [thread1] reconnect 127.0.0.1:27017 (127.0.0.1) ok 2017-07-10T16:53:32.121-0400 E QUERY [thread1] Error: map reduce failed:{ "ok" : 0, "errmsg" : "SyntaxError: missing ) in parenthetical @:1:118\n", "code" : 139, "codeName" : "JSInterpreterFailure" } : _getErrorWithCode@src/mongo/shell/utils.js:25:13 DBCollection.prototype.mapReduce@src/mongo/shell/collection.js:1352:1 @(shell):1:1
The error message appears because the mapReduce functions are strings, not functions. Fixing the types of the mapReduce functions resolves the error:
> var reduceFunction1 = function(keyCustId, valuesPrices) {return Array.sum(valuesPrices);}; > var mapFunction1 = function() {emit(this.cust_id, this.price);}; > db.orders.mapReduce(mapFunction1, reduceFunction1, { out: "map_reduce_example" }) { "result" : "map_reduce_example", "timeMillis" : 247, "counts" : { "input" : 2, "emit" : 2, "reduce" : 1, "output" : 1 }, "ok" : 1 }
Users should consider using native Javascript objects in their application code if the driver supports them.
Original Summary
MapReduce failure with 3.4.6
Original Description
When performing a mapreduce that works on all previous versions including 3.4.5, we are now receiving the error "missing ) in parenthetical map reduce @15:17". A rollback to 3.4.5 from 3.4.6 was required to resolve this.
- is duplicated by
-
SERVER-31374 If map function string ends in a semicolon mapReduce fails silently returning no results
- Closed