Using Mongovue to perform mapreduce operations on MongoDB

Source: Internet
Author: User

Step 1

Open Mongovue and connect to the server that contains the collection "Cities"

Step 2

Right-click on "Cities" collection under "Database Explorer", and select "MapReduce". This would launch the MapReduce view.

Step 3

Write the JavaScript code for MAP function in "Map" tab.

Step 4

Go to "Reduce" tab and enter your JavaScript Reduce code.

Step 5

Go to "Finalize" tab and enter your JavaScript Finalize code.

Step 6

Go to ' in & Out ' tab. Enter the Json code under "{Query}" to exclude cities from USA.

Step 7

We are almost do, but before we run this program and let's just save it to disk first. Click on the small arrow next to "go!" button and select "Save as". You'll be prompted for a filename. Enter a suitable name, and your MapReduce code is saved to a corresponding ". Vumr" file on your computer.

Step 8

We are ready for roll. Just Click the "go!" button, and that ' ll start the MapReduce operation. At the end, you'll see the results in the bottom pane. You can also check the time taken in the StatusBar. Additionally, the shell command is also available under "Learn Shell" toolbox.

This is completes our tutorial. You can check the Learn Shell toolbox, it displays the following command.

Db.runcommand ({mapreduce:cities, map:function map () {var key = this. Countryid;emit (Key, {"Data": [{"Name": this.) City, "lat": this. Latitude, "Lon": this. Longitude}]});} Reduce:function Reduce (key, values) {var reduced = {"Data": []};for (var i in values) {var inter = values[i];for (Var j i N inter.data) {Reduced.data.push (inter.data[j]);}} return reduced;} Finalize:function Finalize (key, reduced) {if (reduced.data.length = = 1) {return {"message": "This country contains onl Y 1 City "};} var min_dist = 999999999999;var city1 = {"Name": ""};var city2 = {"Name": ""};var c1;var c2;var D;for (var i in reduce D.data) {for (Var j in Reduced.data) {if (i>=j) continue;c1 = REDUCED.DATA[I];C2 = reduced.data[j];d = math.sqrt ((c1.la  T-c2.lat) * (C1.lat-c2.lat) + (C1.lon-c2.lon) * (C1.lon-c2.lon)); if (D < min_dist && d > 0) {min_dist = D;city1 = C1;city2 = C2;}}} return {"City1": City1.name, "City2": City2.name, "dist": Min_dist};} Query: {"Countryid": {"$ne": 254}} out: { Inline:1}}); from:http://www.mongovue.com/2011/04/05/how-to-perform-mapreduce-operations-in-mongov 
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.