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 8810111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:02:50+00:00 2026-06-14T03:02:50+00:00

So from what I understand in Couchbase is that one can sort keys* by

  • 0

So from what I understand in Couchbase is that one can sort keys* by using

descending=true

but in my case I want to sort by values instead. Consider the Twitter data in json format, my question is What it the most popular user mentioned?

Each tweet has the structure of:

{
    "text": "",
    "entities" : {
        "hashtags" : [ ... ],
        "user_mentions" : [ ...],
        "urls" : [ ... ]
}

So having used MongoDB before I reused the Map function and modified it slightly to be usable in Couchbase as follows:

function (doc, meta) {
  if (!doc.entities) { return; }

  doc.entities.user_mentions.forEach(
    function(mention) {
      if (mention.screen_name !== undefined) {
        emit(mention.screen_name, null);
      }
    }
  )
}

And then I used the reduce function _count to count all the screen_name occurrences. Now my problem is How do I sort by the count values, rather than the key?

Thanks

  • 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-14T03:02:52+00:00Added an answer on June 14, 2026 at 3:02 am

    The short answer is you cannot sort by value the result of you view. You can only sort by key.

    Some work around will be to either:

    • analyze the data before inserting them into Couchbase and create a counter for the values you are interested by (mentions in your case)

    • use the view you have to sort on the application size if the size of the view is acceptable for a client side sort.

    The following JS code calls a view, sorts the result, and prints the 10 hottest subjects (hashtags):

    var http =  require('http');
    
    var options = {
        host: '127.0.0.1',
        port: 8092,
        path: '/social/_design/dev_tags/_view/tags?full_set=true&connection_timeout=60000&group=true',
        method: 'GET'
    }
    
    http.request(
        options, 
        function(res) {
            var buf = new Buffer(0);
            res.on('data', function(data) {
                buf += data;
            });
            res.on('end', function() {
                var tweets = JSON.parse(buf);
                var rows = tweets.rows;
                rows.sort( function (a,b){ return b.value - a.value } 
                );
    
    
                for ( var i = 0;  i < 10; i++ ) {
                    console.log( rows[i] );
                }
            });
        }
        ).end();
    

    In the same time I am looking at other options to achieve this

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

Sidebar

Related Questions

I found that Maven implies specific directory layout. But I don't understand from here:
From what I understand using $this->db->insert() escapes the values: http://codeigniter.com/user_guide/database/active_record.html#insert Note: All values are
I am experiencing several issues that I can't understand from the first glances. The
I understand from the answer to this question that values of global/static uninitialized int
I am using DBus in a project. I understand from DBus specification that for
As you can understand from title, i modified Settings.cs file.Added some properties, some code
As far as I understand from the documentation the QUdpSocket are async but, still,
I understand from the official documentation on unowned relationships that the app must use
I understand from my research that IE8 does annoying things like forcing itself into
I can very well understand from this Selectutorial what element/tag based descendant selectors are,

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.