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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:09:01+00:00 2026-05-25T22:09:01+00:00

I have a document which looks something like: { _id : ObjectId(4e84f78b26d2046d5d00b5b2), parent_id :

  • 0

I have a document which looks something like:

{
        "_id" : ObjectId("4e84f78b26d2046d5d00b5b2"),
        "parent_id" : 0,
        "ratings" : [
                "20716",
                "78167"
        ],
        "text" : "test"
}

Is it possible to sort by the count of “ratings”? Doing something like:

db.comments.find().sort({rating.count(): -1})

throws an error:

SyntaxError: missing : after property id (shell):0

  • 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-05-25T22:09:01+00:00Added an answer on May 25, 2026 at 10:09 pm

    That’s not directly possible with mongodb [1]

    One solution, if you frequently use this query, is to increment and decrement a field ‘count’ each time you modify the ratings array and sort on that field.

    You document will look like :

    {
        "_id" : ObjectId("4e84f78b26d2046d5d00b5b2"),
        "parent_id" : 0,
        "ratings" : [
                "20716",
                "78167"
        ],
        count : 2
        "text" : "test"
    }
    

    and you query with

    db.comments.find().sort({count: -1})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML document which looks something like this: <meadinkent> <record> <comp_div>MENSWEAR</comp_div> <sty_ret_type>ACCESSORIES</sty_ret_type>
I have got an XML document which looks something like this. <Root> <Info>....</Info> <Info>....</Info>
I have a XML document which looks something like this: <events> <event category=gymnastics subcategory=rhythmic
I have an XML document which contains nodes like following:- <a class=custom>test</a> <a class=xyz></a>
I have something that looks like the following document structure: public class Document {
I have a document which when simplified looks like this: <?xml version=1.0?> <document> <br/>
I have a nested form which looks something like: <FORM METHOD=GET NAME=mainForm ACTION=<%=response.encodeURL(updateForm.jsp)%>> </FORM>
hi i have xml file whitch i want to parse, it looks something like
Okay, if I have a html document that looks a bit like this: <div
I have a user document which has a group field. This field is an

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.