Report diversity data sources-MongoDB and report diversity-mongodb

Source: Internet
Author: User

Report diversity data sources-MongoDB and report diversity-mongodb

MongoDB and other nosql databases have advantages such as scalability and high performance, but their computing capabilities are weaker than traditional SQL databases. For example, MongoDB does not support too many grouping results and does not directly support join operations, the built-in computing engine of the computing report can complement this point. It also has a strong computing capability while gaining the advantages of MongoDB.

We use a grouping instance to understand the process of developing a report using the MongoDB data source for the next computing report.

Report description

The Student score information is stored in MongoDB, including the class, name, score, and subject information. The score table data is as follows:



The total score is summarized and ranked based on the student information. Follow these steps:

Prepare the MongoDB jdbc driver package

The latest version of MongoDB2.6.4 is used here, because the computing report does not contain the MongoDB java driver package. To access MongoDB with a set computing report, you must prepare a MongoDB java driver package in advance (Set Computing report requirements 2.12.2 or a later version of the driver, such as mongo-java-driver-2.12.2.jar ).

Because you want to edit the computing script by using the set computing report designer, you can use the set computing report designer to create a report template, therefore, you need to put the preceding package under the [computing report and set the installer Directory] \ common \ jdbc (the web is deployed in the classpath of the application ). The java driver package for MongoDB is: https://github.com/mongodb/developer-java-driver/releases.

Write computing scripts

Use the set calculator editor to write a set computing script (p1.dfx) to read and compute the table data and return the result set for the report (the result is the result set after running the grid on the right ).

A1: connect to MongoDB. The ip address and port number are localhost: 27017, the database is test, and the user name and password are empty. If you need other parameters, follow the mongo: // ip: port/db? User =... & Password =... Format to continue writing parameters.

A2: Use the find function to retrieve data from MongoDB to form a cursor. The set is score. all fields except _ id are retrieved. We can see that the find function is similar to the find function of MongoDB. The cursor of the set calculator reads and processes data in batches to avoid excessive data volume and memory overflow.

A3: Close the connection.

A4: group by id field.

A5: total score.

A6: rank by the total score, which is the returned result set of the report.

Edit a Report Template

Create a report in The Report designer, set the dataset, and use the dataset type to call the edited script file p1.dfx ).

The dfx file path can be either an absolute or relative path, and the relative path is the dfx home directory configured in the relative options.

 

Edit the report expression and directly use the result set returned by the Set Computing script. The report is no longer grouped or sorted in the report.

Preview the report in the designer and obtain the following results:

Through the above implementation, we can see that using the set computing script can easily complete MongoDB Data Reading and computing, and the external set computing script has a visual editing and debugging environment, the edited script can also be reused (called by other reports or programs ). However, if the script has been debugged and does not need to be reused, It is troublesome to maintain consistency between the two files (the Set Computing script and Report Template, in this case, it is easier to directly use the script dataset of the Set Computing report.

In the script dataset, you can write scripts step by step to complete the computing task. The syntax is the same as that of the Set calculator. You can also directly use the parameters defined in the report. You can use the script dataset as follows:

1. Click "add" in the dataset settings window. The dataset Type dialog box is displayed. Select "script dataset ";

2. Compile the script in the pop-up script dataset editing window;

3. Report expressions, which are the same as those used in datasets.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.