In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
In the previous blog post, I implemented the Group function of MongoDB through an encapsulated Java interface, but did not talk about how to query by date Date. Here is a supplement to how to improve the date Group function of MongoDB.
When implementing the Group function, there are usually some conditions attached, such as querying grouping only if the status is completed or incomplete, or querying eligible packets within a certain date and time period. At this point, if you set the eligible date count in Reduce, you will find that MongoDB completely ignores the date. Why? Because the grammar is wrong.
When querying the grouping of specific conditions in MongoDB, you should put those conditions in Condition. For more information on how to do this, look at the following code.
Public String getCTOStatistic () throws Exception {String ctoTaskType = getParameterValue ("ctoTaskType"). ToString (); String startDate = getParameterValue ("startDate"). ToString (); String endDate = getParameterValue ("endDate"). ToString (); DBObject initial = new BasicDBObject (); DBObject index = new BasicDBObject (); BasicDBObject cond = new BasicDBObject (); BasicDBObject dateCondition = new BasicDBObject (); index.put ("count", 0) Index.put ("ctoPerson", "); initial.put (" ctoPerson ", index); cond.put (" ctoStatus "," Finished "); if (StringUtils.isNotEmpty (ctoTaskType)) {cond.put (" taskId ", ctoTaskType);} if (StringUtils.isNotEmpty (startDate)) {dateCondition.append (" $gte ", DateUtil.toDate (startDate)) } if (StringUtils.isNotEmpty (endDate)) {dateCondition.append ("$lt", DateUtil.toDate (endDate));} cond.put ("jobCreateTime", dateCondition); String reduce = "function (doc, out) {" + "out.ctoPerson.count = out.ctoPerson.count+=1;" + "out.ctoPerson.ctoPerson = doc.ctoPerson" "+"} "; BasicDBList group = (BasicDBList) ctoJobService.group (new String [] {" ctoPerson "}, cond, initial, reduce, null); this.jsonResult = group.toString (); return SUCCESS;}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.