Uploaded image for project: 'PHP Driver: Library'
  1. PHP Driver: Library
  2. PHPLIB-309

mapReduce jsMode option should be unset by default

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Blocker - P1 Blocker - P1
    • 1.3.0
    • Affects Version/s: 1.2.0
    • Component/s: None
    • Labels:
      None
    • Environment:
      Ubuntu 14.04 LTS x64
      Linux kernel 3.13.0-125-generic
      mongos version v3.6.2
      mongod version v3.6.2
      PHP 7.1.12

      Hi,
      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:

      MongoDB\\Driver\\Exception
      RuntimeException: unknown m/r field for sharding: jsMode in /opt/myproject/vendor/mongodb/mongodb/src/Operation/MapReduce.php:247
      Stack trace:
      #0 /opt/myproject/vendor/mongodb/mongodb/src/Operation/MapReduce.php(247): MongoDB\\Driver
      Server->executeCommand('my_command', Object(MongoDB\\Driver
      Command), Object(MongoDB\\Driver
      ReadPreference))
      #1 /opt/myproject/vendor/mongodb/mongodb/src/Collection.php(861): MongoDB\\Operation\\MapReduce->execute(Object(MongoDB\\Driver
      Server))

      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.

      Thanks,

      SAMPLE CODE TO CAUSE THE ERROR ON THE SERVER:

      function mapFunction() { emit(this._id, this); }
      function reduceFunction(testInputDocId, testResults) {}
      
      db.input_collection.mapReduce( 
      	mapFunction,
      	reduceFunction,
      	{
      		out: { 
      			merge: "output_collection",
      			sharded: true
      		},
              // THIS LINE CAUSES DRAMA, WHETER THE VALUE IS true OR false. 
              // HOWEVER THE FIX IS EASY, JUST REMOVE THE LINE ENTIRELY
              jsMode: false,
      		query: { _id: ObjectId("5a14b412228e9b5bc582fe9d") }
      	}
      )
      

      SAMPLE CODE TO CAUSE THE ERROR IN PHP:

      $mapReduceOutOption = [
              'merge'		=> self::COLLECTION_NAME,
      
              // THIS LINE CAUSES THE ERROR, INDIRECTLY
              'sharded'	=> true
      ];
      
      $coll->getCollection()->mapReduce($mapFunction, $reduceFunction, $mapReduceOutOption, [
              'query' => [ '_id' => [ '$in' => $arrIds ]],
              'scope' => $testParams
      ]);
      

            Assignee:
            katherine.walker@mongodb.com Katherine Walker (Inactive)
            Reporter:
            mlis mils
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: