A study on the diversity of the data source in the run-dry collection report MongoDB

Source: Internet
Author: User

The diversity data source is more and more common in the report development, and the efficient support of the run-dry set report to the diversity data source makes this kind of report development very simple, the data source type supported by the current set of reports, in addition to the traditional relational database, also supports: TXT text,Excel,JSON,HTTP,Hadoop,MongoDB, and more.

NoSQL databases such as MongoDB have the advantages of scalability and high performance, but the computational power is weaker than traditional SQL (such as MongoDB 's grouping result is not too large and does not directly support join calculations, and the built-in computing engine of the set-up report can supplement this, while gaining the advantage of MongoDB with strong computational power.

Here's a grouping instance to see the process of developing a report using a MongoDB data source.

Report Description

student performance information is stored in MongoDB , including classes, names, scores, subjects and other information, scores table (score) data content as follows:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/52/1E/wKioL1RkCQKTrmlBAAIMouLUlK8811.jpg "style=" float: none; "title=" report5_multisource_mongodb_1.jpg "alt=" Wkiol1rkcqktrmlbaaimoululk8811.jpg "/>

According to the Student information summary total scores, and ranking. The following steps are implemented:

Preparing the MongoDB JDBC driver package

     Here is the latest version of Mongodb2.6.4 Mongodb java driver package. Use a collection report to access the mongodb must be prepared in advance mongodb driver package (report requirements 2.12.2).

Since you are editing the script separately using the Collector Editor, and then using the Set up Report Designer to make the report template, you need to put the above package into []\common\jdbc the Collection report and the Collector installation directory (when the Web deployment is placed in the classpath of the app ). the Mongodb Java driver package is:https://github.com/mongodb/mongo-java-driver/releases .

writing a calculation script

Use the Collector Editor to write the set-up script (p1.dfx), complete the table data read calculation, and return the result set for the report (the right side is the result of the grid run).

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/52/20/wKiom1RkCJXyiKHhAAHVEPktrwk911.jpg "style=" float: none; "title=" report5_multisource_mongodb_2.jpg "alt=" Wkiom1rkcjxyikhhaahvepktrwk911.jpg "/>

A1: Connect mongodb,IP and port number is localhost:27017, database is test, username and password are empty. If you need other parameters, you can follow mongo://ip:port/db?user=...&password= ... format to continue writing parameters.


A2: Use the Find function to take a number from MongoDB to form a cursor. The collection is score, removing all fields except _id. You can see that the find function is similar to MongoDB's Find function. The collector's cursors are read and processed in batches to avoid excessive amounts of data and memory overflow situations.


A3: Closes the connection.

A4: GROUP by ID field.

A5: summary total.

A6: Returns the result set for the report by total score.

edit a report template

you first create a new report in the collection Report Designer, set the dataset, and use the "Collector " DataSet type to invoke the edited script file (p1.dfx):

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/52/1E/wKioL1RkCQPzCKTCAADdDhJ8uCA534.jpg "style=" float: none; "title=" report5_multisource_mongodb_3.jpg "alt=" Wkiol1rkcqpzcktcaadddhj8uca534.jpg "/>

where theDFX file path can be either an absolute path or a relative path, relative paths are configured in the relative option of the DFX home directory.

Edit the report expression, use the result set returned by the collection script directly, and no longer group the sorting in the report to complete the report production:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/52/20/wKiom1RkCJbgELRzAABwVE-dlw4903.jpg "style=" float: none; "title=" report5_multisource_mongodb_4.jpg "alt=" Wkiom1rkcjbgelrzaabwve-dlw4903.jpg "/>


Previewing the report in the designer can result in the following:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/52/1E/wKioL1RkCQTDG-SeAACaw7TlxRY530.jpg "title=" Report5_multisource_mongodb_5.jpg "style=" Float:none; "alt=" wkiol1rkcqtdg-seaacaw7tlxry530.jpg "/>


As can be seen from the above implementation, the use of the collector script can easily complete the MongoDB data read calculation, and the external set of the script has a visual editing debugging environment, the edited script can also be reused (by other reports or programs called). However, if the script has been debugged and does not need to be reused, it would be cumbersome to maintain the consistency of the two files (both the set and report templates), which makes it easier to use the script dataset directly for the set report.

in the script dataset, you can step through the script to complete the calculation tasks, the syntax is consistent with the concentrator, and you can use the report-defined parameters directly. This can be done using a script dataset:

1. Click the "Add" button in the DataSet Settings window to pop up the dataset Type dialog and select " script data set ";

2. Write the script in the Popup Script DataSet editing window;


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/52/20/wKiom1RkCJfwng4wAAFpxvuh5c4593.jpg "style=" float: none; "title=" report5_multisource_mongodb_6.jpg "alt=" Wkiom1rkcjfwng4waafpxvuh5c4593.jpg "/>

3. report expressions, consistent with the use of the collector dataset, are no longer mentioned.


A study on the diversity of the data source in the run-dry collection report MongoDB

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.