title: How can I execute a shell script file by the MongoTemplate
body: <p>I need to execute my x-report.js file using MongoTemplate and get Collections(output for displaying in UI). I tried in many ways, but i didn't find any solution.</p>
  
  <pre><code>  StringBuilder text = new StringBuilder();
      BufferedReader br = new BufferedReader(new FileReader(
              new ClassPathResource("x-report.js").getFile()));
      try {
          while (true) {
              String line = br.readLine();
              if (line == null)
                  break;
              text.append(line).append("\n");
          }
      } finally {
          try { br.close(); } catch (Exception ignore) {}
      }
      BasicDBObject obj = new BasicDBObject();
      obj.append("$eval", text.toString());
      System.out.println(mongoTemplate.executeCommand(obj));
  </code></pre>
  
  <p>Am using Mongo 3.2.0 version, But $eval has been removed in MongoDB 3+ version. Then i tried with "command"</p>
  
  <pre><code>   com.mongodb.DB mongoDb = mongoTemplate.getDb();
      CommandResult cr = mongoDb.command(mongoScript());
      System.out.println("Command Restults-------&gt;" + cr.size());
  
  
  private String mongoScript() {
      String st = "db.ReportData.find({\"createdDate\": {$gte:ISODate(\"2017-03-31T00:00:00.000Z\"), $lte:ISODate(\"2017-04-20T00:00:00.000Z\")}})";
      return st;
  }
  </code></pre>
  
  <p>In this way also i am unable to execute my script. Please someone help me.</p>