MongoDB's group detailed success stories

Source: Internet
Author: User

/** * Query Financial statements * @author Liupeng * @param timestart * @param timeend * @return *///public list<keyrequest> FINDBYTIMEF Orfinal (String Timestart, String timeend) {public list<dbobject> findbytimeforfinal (string Timestart, String   Timeend) {basicdbobject key = new Basicdbobject (); Key.put ("Kq_timer_start", true); GroupBy conditions Basicdbobject cond = new Basicdbobject ("Kq_timer_start", New Basicdbobject ("$gte", Timestart). Append ("$lt              Timeend);//query Where condition basicdbobject initial = new Basicdbobject (); Initial.put ("Cou", 0);     Need to query out the content initial.put ("Kq_autosum", "" ");  Need to query out the content initial.put ("Kq_accountsum", "" "); The content that needs to be queried is string reduce = "function (obj,out) {" + "out.cou++;" + "Out.kq_autosum = out.kq_autosum+obj.kq_autosum+ ' _ ';" + "Out.kq_accountsum = out.kq_accountsum+obj.kq_accountsum+ ' _ ';}"; Basicdblist returnlist = (basicdblist) keyrequest.group (key, cond, initial, reduce); System.out.println (returnlist); list<dbobject> list = new arraylist<dbobject> (); object[] o = Returnlist.toarray (); for (int i = 0; i < o.length; i++) {DBObject dbobject = (dbobject) o[i];list.add (dbobject);} Return list;//can print out any value in Basicdblist in the form of/*system.out.println (returnlist); object[] o = Returnlist.toarray (); for ( int i = 0; i < o.length; i++) {DBObject dbobject = (dbobject) o[i]; System.out.println (Dbobject.get ("kq_id"));} */}

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.