code: public List executeNativeQuery(String jsonClause, EntityMetadata entityMetadata)
      {
          List entities = new ArrayList();
          String[] tempArray = jsonClause.split("\\.");
          String tempClause = tempArray[tempArray.length - 1];
  
          if (tempClause.contains("findOne(") || tempClause.contains("findAndModify("))
          {
              DBObject obj = (BasicDBObject) executeScript(jsonClause);
              populateEntity(entityMetadata, entities, obj);
              return entities;
  
          }
          else if (tempClause.contains("find(") || jsonClause.contains("aggregate("))
          {
              jsonClause = jsonClause.concat(".toArray()");
              BasicDBList list = (BasicDBList) executeScript(jsonClause);
              for (Object obj : list)
              {
                  populateEntity(entityMetadata, entities, (DBObject) obj);
              }
              return entities;
  
          }
          else if (tempClause.contains("count(") || tempClause.contains("dataSize(")
                  || tempClause.contains("storageSize(") || tempClause.contains("totalIndexSize(")
                  || tempClause.contains("totalSize("))
          {
              Long count = ((Double) executeScript(jsonClause)).longValue();
              entities.add(count);
              return entities;
  
          }
          else if (tempClause.contains("distinct("))
          {
              BasicDBList list = (BasicDBList) executeScript(jsonClause);
              for (Object obj : list)
              {
                  entities.add(obj);
              }
              return entities;
  
          }
          else if (jsonClause.contains("mapReduce("))
          {
              final MapReduceCommand command = parseMapReduceCommand(jsonClause);
              final MapReduceOutput output = mongoDb.getCollection(command.getInput()).mapReduce(command);
  
              final BasicDBList list = new BasicDBList();
              for (final DBObject item : output.results())
              {
                  list.add(item);
              }
              return list;
          }
          else
          {
              BasicDBList list = (BasicDBList) executeScript(jsonClause);
              for (Object obj : list)
              {
                  entities.add(obj);
              }
              return entities;
          }
      }
docs: Execute native query.
  
  @param jsonClause
  the json clause
  @param entityMetadata
  the entity metadata
  @return the list