SELECT           mySQL                                        db.runCommand({                                             ...
Upcoming SlideShare
Loading in...5
×

Sql to-mongo db

716

Published on

Published in: Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
716
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
10
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Sql to-mongo db

  1. 1. SELECT mySQL db.runCommand({ MongoDB Dim1, Dim2, 1 mapreduce: "DenormAggCollection", SUM(Measure1) AS MSum, query: { 2 COUNT(*) AS RecordCount, filter1: { $in: [ A, B ] }, AVG(Measure2) AS MAvg, 3 filter2: C, MIN(Measure1) AS MMin filter3: { $gt: 123 } MAX(CASE }, WHEN Measure2 < 100 4 map: function() { emit( THEN Measure2 { d1: this.Dim1, d2: this.Dim2 }, END) AS MMax { msum: this.measure1, recs: 1, mmin: this.measure1,FROM DenormAggTable mmax: this.measure2 < 100 ? this.measure2 : 0 }WHERE (Filter1 IN (’A’,’B’)) );}, AND (Filter2 = ‘C’) 5 reduce: function(key, vals) { AND (Filter3 > 123) var ret = { msum: 0, recs: 0, mmin: 0, mmax: 0 };GROUP BY Dim1, Dim2 1 for(var i = 0; i < vals.length; i++) {HAVING (MMin > 0) ret.msum += vals[i].msum;ORDER BY RecordCount DESC ret.recs += vals[i].recs;LIMIT 4, 8 if(vals[i].mmin < ret.mmin) ret.mmin = vals[i].mmin; if((vals[i].mmax < 100) && (vals[i].mmax > ret.mmax)) ret.mmax = vals[i].mmax; }1 Grouped dimension columns are pulled return ret; out as keys in the map function, }, reducing the size of the working set. finalize: function(key, val) { 62 Measures must be manually aggregated. 7 val.mavg = val.msum / val.recs; return val;3 Aggregates depending on record counts }, Revision 4, Created 2010-03-06 Rick Osborne, rickosborne.org must wait until finalization.4 Measures can use procedural logic. out: result1, verbose: true5 Filters have an ORM/ActiveRecord- }); looking style. db.result1.6 Aggregate filtering must be applied to the result set, not in the map/reduce. find({ mmin: { $gt: 0 } }).7 Ascending: 1; Descending: -1 sort({ recs: -1 }). skip(4). limit(8);
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×