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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:07:10+00:00 2026-05-20T00:07:10+00:00

Say I have the following documents in my database: a_doc1, a_doc2, b_doc1, and b_doc2

  • 0

Say I have the following documents in my database: a_doc1, a_doc2, b_doc1, and b_doc2

All these documents are of the following format

<doc>
  ....
  <updatedTime>2011-02-07T14:41:02.133-05:00</updatedTime>
  ....
</doc

>

The value of the “updatedTime” element is inserted when the document is created using the fn:current-dateTime()

Now I am trying to do the following:

  1. find all documents whose name starts with “a_”
  2. order these documents by their <updatedTime> element in descending order
  3. Return the first document name from the descending order

I tried the following:

for $doc_name in db:list()
  where fn:starts-with($doc_name, 'a_')
    order by xs:dateTime(doc($doc_name)/updatedTime) descending
      return $doc_name

Say “a_doc1” is created at “2011-02-07T14:40:00.78-05:00” and “a_doc2” is created at “2011-02-07T14:41:02.133-05:00”, the desired output is a_doc2. In short the document name(starting with a_) of the most recent document created must be returned.

When I try my sample code, the output returned is : [a_doc1, a_doc2].
The expected output is: [a_doc2, a_doc1].

Thanks,
Sony

  • 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-20T00:07:11+00:00Added an answer on May 20, 2026 at 12:07 am
    order by dateTime(doc($doc_name)/updatedTime/text())
    

    Instead of this use:

    order by xs:dateTime(doc($doc_name)/updatedTime)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have the following documents Article { Comment: embedMany } Comment {
Let’s say you have the following mongoid documents: class User include Mongoid::Document embeds_one :name
I have the following code that returns rows from a database when a form
Let's say I have a dataset like the following: { _id : ObjectId(4dd51c0a3f42cc01ab0e6506), views
My setup is like this: Admin search for orders depending on say address, or
Hi friends, Am newbie for windows Development .i have created Grid With tabcontrol using
I'm migrating a GAE/Java app to Python (non-GAE) due new pricing, so I'm getting
I am using jqPlot javascript library ( http://www.jqplot.com/ ) for graphs and charts in
I'd like to know if there exists a program that can read DTD specifications,
I need to get the starting position of new line when looping through a

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.