MongoDB's mapreduce application of external variables using key parts SPRINGMVC;

Source: Internet
Author: User

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;

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.