This is my first JIRA ticket, so please forgive me if I have missed anything.
In production, I try to run map/reduce with a sharded input-collection and a sharded output-collection. The input collection is fine, however when I use a sharded output collection (with the 'sharded: true' option), I get the following error:
RuntimeException: unknown m/r field for sharding: jsMode in /opt/myproject/vendor/mongodb/mongodb/src/Operation/MapReduce.php:247
#0 /opt/myproject/vendor/mongodb/mongodb/src/Operation/MapReduce.php(247): MongoDB\\Driver
#1 /opt/myproject/vendor/mongodb/mongodb/src/Collection.php(861): MongoDB\\Operation\\MapReduce->execute(Object(MongoDB\\Driver
On the server-side there is already a ticket for this issue, since 2012 (https://jira.mongodb.org/browse/SERVER-5448). The issue being:
A mapReduce command issued against a sharded collection will fail with the message "unknown m/r field for sharding: jsMode"
On the server-side this issue is not a blocker, as the user can simply avoid setting the jsMode flag altogether.
When using php, I avoid setting the jsMode flag in my code, but after execution is handed over to the mongodb php extension I get the error.
So it seems that the php extension is setting the jsMode flag under the hood, when the server does not support it.
This means that in php, map/reduce does not work with a sharded output-collection
I can only imagine that the solution would be to avoid setting a default value for jsMode in the extension, but that may have knock-on effects.
In any case, I would appreciate suggestions for a workaround, as I have a DB with nearly a TB of data, so sharding is necessary.
SAMPLE CODE TO CAUSE THE ERROR ON THE SERVER:
SAMPLE CODE TO CAUSE THE ERROR IN PHP: