code: private MapReduceCommand parseMapReduceCommand(String jsonClause)
      {
          String collectionName = jsonClause.replaceFirst("(?ms).*?\\.\\s*(.+?)\\s*\\.\\s*mapReduce\\s*\\(.*", "$1");
          if (collectionName.contains("getCollection"))
          {
              collectionName = collectionName
                      .replaceFirst(".*getCollection\\s*\\(\\s*(['\"])([^'\"]+)\\1\\s*\\).*", "$2");
          }
  
          DBCollection collection = mongoDb.getCollection(collectionName);
  
          String body = jsonClause.replaceFirst("^(?ms).*?mapReduce\\s*\\(\\s*(.*)\\s*\\)\\s*;?\\s*$", "$1");
          String mapFunction = findCommaSeparatedArgument(body, 0).trim();
          String reduceFunction = findCommaSeparatedArgument(body, 1).trim();
  
          String query = findCommaSeparatedArgument(body, 2).trim();
          DBObject parameters = (DBObject) JSON.parse(query);
          DBObject mongoQuery;
          if (parameters.containsField("query"))
          {
              mongoQuery = (DBObject) parameters.get("query");
          }
          else
          {
              mongoQuery = new BasicDBObject();
          }
  
          return new MapReduceCommand(collection, mapFunction, reduceFunction, null, MapReduceCommand.OutputType.INLINE,
                  mongoQuery);
      }
docs: Parses the map reduce command.
  
  @param jsonClause
  the json clause
  @return the map reduce command