The sequencer assists in localizing the MongoDB computation

Source: Internet
Author: User

for localized languages (for example: Chinese), MongoDB is sorted by UNICODE encoding, not by encoding in the local language. Using esproc with MongoDB makes it easy to sort the localized languages (for example: Chinese in alphabetical order). Let's take the Chinese as an example to look at the specific approach.

the collection in MongoDB person saves the name and gender as follows:

>db.person.find ()

{"_id": ObjectId ("544e4e070f03ad39eb2bf498"), "name": "Song Jiang ", "Gender": " male "}

{"_id": ObjectId ("544e4e070f03ad39eb2bf499"), "name": " li Kui ", "Gender": " male "}

{"_id": ObjectId ("544e4e070f03ad39eb2bf49a"), "name": " Wu ", "Gender": " male "}

{"_id": ObjectId ("544e4e070f03ad39eb2bf49b"), "name": " Chungai ", "Gender": " male "}

{"_id": ObjectId ("544e4e070f03ad39eb2bf49c"), "name": " Gongsun wins ", "Gender": " male "}

{"_id": ObjectId ("544e4e070f03ad39eb2bf49d"), "name": " lu Zhishen ", "Gender": " male "}

{"_id": ObjectId ("544e4e070f03ad39eb2bf49e"), "name": " Wu Song ", "Gender": " male "}

{"_id": ObjectId ("544e4e070f03ad39eb2bf49f"), "name": " Nanxiao ", "Gender": " male "}

{"_id": ObjectId ("544e4e070f03ad39eb2bf4a0"), "name": " Yang Zhiwang ", "Gender": " male "}

{"_id": ObjectId ("544E4E070F03AD39EB2BF4A1"), "name": " erniang ", "Gender": " female "}

{"_id": ObjectId ("544E4E070F03AD39EB2BF4A2"), "name": " sanniang ", "Gender": " female "}

{"_id": ObjectId ("544e4e080f03ad39eb2bf4a3"), "name": "燕青", "Gender": " male "}

...

directly with MongoDB 's sort function, not sorted by pinyin:

>db.person.find ({},{"name": 1, "Gender": 1, "_id": 0}). Sort ({"Name": 1})

{"Name": " Gongsun wins ", "Gender": " male "}

{"Name": " Wu uses ", "Gender": " male "}

{"Name": " erniang ", "Gender": " female "}

{"Name": "Song Jiang ", "Gender": " male "}

{"Name": " sanniang ", "Gender": " female "}

{"Name": " Chungai ", "Gender": " male "}

{"Name": " li Kui ", "Gender": " male "}

{"Name": " Yang Zhiwang ", "Gender": " male "}

{"Name": " Wu Song ", "Gender": " male "}

{"Name": "燕青", "Gender": " male "}

{"Name": " Nanxiao ", "Gender": " male "}

{"Name": " lu Zhishen ", "Gender": " male "}

...

The script to assist MongoDB with Esproc is as follows:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/54/59/wKioL1SAAM3T7S99AAC5EaColj0204.jpg "style=" float: none; "title=" esproc_mongodb_local_sort_1.jpg "alt=" Wkiol1saam3t7s99aac5eacolj0204.jpg "/>

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

A2: Use the Find function to take a number from MongoDB to form a cursor. The collection is person, the filter condition is empty, and the specified key is name and gender. You can see that the find function is similar to the Find function of Mongdb . Esproc cursors are read and processed in batches to avoid excessive amounts of data and memory overflow situations.

A3: Because the amount of data is not big, so here fetch all records of the subject.

A4: Use sort to sort by name in ascending order. The language in which the sort is used is Chinese. Other localized languages supported by the collector, see later.

The result of the operation is:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/54/5A/wKiom1SAAD-hcT-3AACH2MZ6Tn8330.jpg "style=" float: none; "title=" esproc_mongodb_local_sort_2.jpg "alt=" Wkiom1saad-hct-3aach2mz6tn8330.jpg "/>

It is necessary to notethat Esproc does not contain MongoDB 's java driver package. to access MongoDB with Esproc, you must advance the Java driver package for MongoDB (requires 2.12.2 or more, such as Mongo-java-driver-2.12.2.jar) is placed in the [esproc installation directory ]\common\jdbc .

EsprocAssistMongodbthe computed script is easily integrated intoJava, just add a rowA5, writtenResult A4you can sendJavaOutputResultSetThe result of the form, the specific code referenceEsprocTutorials. Similarly, withJavacalledEsprocAccessMongodbmust also beMongdbof theJavaThe driver package is placedJavaof the programClasspaththe.

the Java driver package for MongoDB is:https://github.com/MongoDB/mongo-java-driver/releases.




This article is from the High performance report data calculation blog, so be sure to keep this source http://report5.blog.51cto.com/8028595/1586288

The sequencer assists in localizing the MongoDB computation

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.