Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8950119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:22:45+00:00 2026-06-15T13:22:45+00:00

I need to implement Popular Keyword in my web app so that most searched

  • 0

I need to implement “Popular Keyword” in my web app so that most searched keywords will show there.. For that i have created a db in mongo. I need to retrieve data from mongo so that mostly occuring keywords should sort and should return to my page. In sql it is just like as,
select names,count(names) from keyword_db group by names order by names;

need both java code and mongo shell query..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:22:46+00:00Added an answer on June 15, 2026 at 1:22 pm

    You might want to try for the mongo shell query (I’m sorting in descending order:

    db.keyword_db.aggregate ( [ 
       { $group: { _id: "$names", count: { $sum: 1 } } }, 
       { $sort: { count: -1 } }  ] )
    

    For the Java version:

        DBCollection myColl = db.getCollection("keyword_db"); 
    
        // for the $group operator
        DBObject groupFields = new BasicDBObject( "_id", "$names");
        groupFields.put("count", new BasicDBObject( "$sum", 1));
    
        DBObject group = new BasicDBObject("$group", groupFields );
    
        // for the $sort operator
    
        DBObject sortFields = new BasicDBObject("count", -1);
    
        DBObject sort = new BasicDBObject("$sort", sortFields );
    
        // run the aggregation
    
        AggregationOutput output = myColl.aggregate(group, sort);
    
        System.out.println( output.getCommandResult() );
    

    The following page may help you also:
    http://docs.mongodb.org/manual/reference/sql-aggregation-comparison/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume we have a popular site. We need to implement mail-like messaging between users.
I need to implement SURF algorithm in objc iOS. I have searched on openCV
Need to implement an app that has a feature to play sounds. Each sound
I need to develop a lightweight web application, it will: have a simple webgui
I need to implement an efficient excel-like app. I'm looking for a data structure
I need to implement the following: There is a table A which is supposed
I need to implement a simple monitoring app in Excel. It is for monitoring
i need to implement a messaging scenario that consumes messages from throusands of destinations
I need to implement a method that concatenates different characters into a char* without
I need to implement simple file watcher utility. I have decided to implement this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.