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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:07:42+00:00 2026-06-10T08:07:42+00:00

After trying this solution and getting one step further i have another question regarding

  • 0

After trying this solution and getting one step further i have another question regarding mongodb.

My question is:

How can i sort the output of:

doc = {_id : 16, days : { 1 : 123, 2 : 129, 3 : 140, 4 : 56, 5 : 57, 6 : 69, 7 : 80 }};
db.so.insert(doc);

map = function() {
  emit(this._id, this.days["1"]);
  emit(this._id, this.days["3"]); 
  emit(this._id, this.days["7"]); 
}

reduce = function (k, vals) {
  var sum = 0;
  vals.forEach(function (v) {sum += v;});
  return sum;
}

res = db.so.mapReduce(map, reduce, {out : {inline : 1}});
res.find();

The Output is like this:

"results" : [
    {
            "_id" : 16,
            "value" : 225
    },
    {
            "_id" : 33,
            "value" : 230
    },
    {
            "_id" : 302,
            "value" : 274
    }

]

Now i want to sort the result with:

res.find().sort({ "results.value":-1 });

which results in this error:

Sat Mar 31 01:15:45 TypeError: res.find().sort({'results.value':-1}) is not a function (shell):1

Does anybody can help me ?

  • 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-10T08:07:44+00:00Added an answer on June 10, 2026 at 8:07 am

    Here’s an example of the same query using the MongoDB 2.2 Aggregation Framework:

    db.so.aggregate(
      { $project : {
         '_id' : 1,
         'value' : { $add : ["$days.1","$days.3","$days.7"] },
      }},
      { $sort: { 'value': -1 }}
    )
    

    .. and the output:

    {
        "result" : [
            {
                "_id" : 302,
                "value" : 274
            },
            {
                "_id" : 33,
                "value" : 230
            },
            {
                "_id" : 16,
                "value" : 225
            }
        ],
        "ok" : 1
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is mainly out of curiosity (I have a different working solution to
Have any of you had this problem before? I'm trying to obfuscate a solution
I have a page with several forms. I am trying to submit one of
I have been trying to install the Ruby PG gem, but kept getting the
I am really stuck on this one. Website is almost finished. Just trying to
After spending a good 3 to 4 hours on google trying to find any
I'm trying to use the very nice ConfirmerAjaxLink from Visural . However, I'm getting
I am trying to load big image files in Java and i am getting
I'm sorry in advance if this question is flawed. I'm pretty new to databases(I
ok I have two strings. (I use this for a language library system to

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.