In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.