I have implemented a query in mongo. I need to put the groupobj and sortobj in the pipeline as well.Since there will be lot of queries with a little variations I am thinking of using JAVA Reflection.
I have gone through the tutorial for JAVA Reflection and understood the concepts but I am not sure how to fit it into my requirement.
Any help !!
switch (dataId) {
        case ApplicationConstants.TOP_QUERIES_:
            // table = db.getCollection("tq");
            table = db.getCollection(MongoConstants.TOP_QUERY);
                MatchQuery.topQuery(matchObj, timePeriod);
            pipeline.add(matchObj);
            // group on term & totalcount
            final BasicDBObject groupObj = new BasicDBObject();
            groupObj.put("$group", new BasicDBObject(
                    ApplicationConstants._ID_FIELD, "$term").append(
                    ApplicationConstants.TOTAL_COUNTS, new BasicDBObject(
                            "$sum", "$count")));
            pipeline.add(groupObj);
            DBObject sort = null;
            // sort operation by count and alphabetically by term(storing in
            // _id)
            BasicDBObject sortByCount = null;
            if (filterObj.isSortOrder()) {
                sortByCount = new BasicDBObject(
                        ApplicationConstants.TOTAL_COUNTS, 1);
            } else {
                sortByCount = new BasicDBObject(
                        ApplicationConstants.TOTAL_COUNTS, -1);
            }
            sort = new BasicDBObject("$sort", sortByCount.append(
                    ApplicationConstants._ID_FIELD, 1));
            pipeline.add(sort);
            break;
Aucun commentaire:
Enregistrer un commentaire