Long interval = 900000;
Long startTime = new Date ("2016/03/01 01:00:00"). GetTime ();
Long endTime = new Date ("2016/03/31 23:59:59"). GetTime ();
String taguid= (String) arr.get (i);
Query query = query.query (Criteria.where ("Tagguid"). In (Taguid));//Query Filter CriteriaQuery.addcriteria (Criteria.where ("Mday"). Is (1));//Add Filter conditions mapreduceoptions options = mapreduceoptions.options ();//Set reduce configuration item MAP scope = new HashMap (); Scope.put ("Interval", interval); Scope.put ("StartTime", startTime); options.scopevariables (Scope). Verbose (true). Outputtypeinline (); //mapreduce external variable insertionString MapFunction1 = "function () {" + "var ssecond=new Date (this.) Atime). GetTime (), "+" Tag=parseint ((ssecond-starttime)/interval); " + "emit ({guid:this. Tagguid,time:tag},{taguid:this. Tagguid,atime:this. Atime,value:this. Tagvalue,year:this.myear,month:this.mmonth,day:this.mday,seeid:this. Seeid})} ";//Map Method AuthoringString reducefunction = "function (key,values) {return values[0];}";//Reduce method Writing mapreduceresults<returnmessage> result = mongotemplate.mapreduce (query, "Hdata03", MapFunction1, Reducefunction,options, Returnmessage.class);//Method invocationIterator<returnmessage> it = Result.iterator ();//Get Results LongP=0; while(It.hasnext ()) {ReturnMessage message= It.next ();//custom entity class containerString key= (String) jsonobject.fromobject (Message.getid ()). Get ("GUID"); String Insertsql= "INSERT into T_base_data (data) VALUES ('" +message.getvalue () + "')";//inserting PostgreSQLBasedao.updatebysql (Insertsql); }
The last insert Postgesql did the loop insert is very unscientific, wasting a lot of time;
This paper mainly demonstrates the use of a mapreduce global variable;
Other loops are just tests, a little cumbersome;
MongoDB's mapreduce application of external variables using key parts SPRINGMVC;