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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:40:39+00:00 2026-05-31T18:40:39+00:00

class Example(Document): comments = ListField(field=EmbeddedDocumentField(‘Comment’), db_field=’z’) class Comment(EmbeddedDocument): comment = StringField() date = DateTimeField()

  • 0
class Example(Document):
    comments =  ListField(field=EmbeddedDocumentField('Comment'), db_field='z')

class Comment(EmbeddedDocument):
    comment = StringField()
    date = DateTimeField()

how can I reverse the result of comments listfield by Comment EmbeddedDocument’date?
my incorrect code.. is like..

Example.objects().order_by('-comments__date')

Is there a way to reverse ListField by embeddedDocument’s date?
or
just reverse listfield?

  • 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-31T18:40:40+00:00Added an answer on May 31, 2026 at 6:40 pm

    In mongoDB you return items matched by the find statement. So Doing an:

    Example.objects().order_by('-comments__date')
    

    You are just ordering Example objects by the latest comment date. The query language is for matching so does not change the results / order of the returned list. You could use a SortedListField that ensures a list is sorted on save if you need to ensure order. However, there is a possible race condition here as it sets the whole list. The $push operator is best, but it means comments will be a stack and oldest will be appended to the end.

    An alternative schema might be desired with comments in their own collection or in mongoDB 2.2 the aggregation framework could be used to sort the comments themselves.

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

Sidebar

Related Questions

Ubuntu 10.04.3 LTS mongodb-1.2.2-1ubuntu1.1 django 1.3 mongoengine-0.5.2 pymongo-2.1.2 model: class User(Document): email = StringField(required=True)
For example.. class Example(Document): up = IntField() down = IntField() and.. I want to
Is it possible to get real polymorphism in Mongoid? Example: class Company include Mongoid::Document
Here's the example. webBrowser1.Document.Body.InnerHtml contains: <img id=image1 src=myImage.gif> and in my MyWebBrowser class I
Why can't I set $_SERVER['DOCUMENT_ROOT'] as attribute? see example code class foo { private
Given: class example { public: std::vector<std::vector<int>> a; int b; } func() { example e;
I have a model: class Example(models.Model): unique_hash = models.CharField(max_length=32,unique=True) content = models.FileField(upload_to='source',blank=True,verbose_name=HTML Content File)
In the following class: public class Example<T> where T : IComparable { private T
I have a model defined as below: class Example(models.Model): user = models.ForeignKey(User, null=True) other
struct GPattern() { int gid; .... } class Example() { public: void run(string _filename,

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.