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

  • Home
  • SEARCH
  • 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 8078477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:48:33+00:00 2026-06-05T15:48:33+00:00

I am developing a webapp using PHP and MongoDB. In this app I keep

  • 0

I am developing a webapp using PHP and MongoDB. In this app I keep two collections. One to keep data about files and one to keep track about download events for each file.

I need to get the 10 latest downloaded files but I know joins is not an option. The events document only stores the file id and the other collection stores the thumbnail.

Right now I first get the 10 recently downloaded files and order it by date and the order is fine but then I use this array of files (their ids) and make a where_in query where I look for files whos id is present in the ids array. This also works fine (I get the thumbnails for the selected files) but I cannot keep the order anymore. The most recently downloaded file is not longer on top.

How can I keep the order of the ids without looping through them thus making 10 new queries instead of just one?

I cannot change the schema because I got over 40.000 documents 🙂

UPDATE

In short this is what I want to do:

  1. Get all the IDs of the 10 recently downloaded files. Sorted by download timestamp.
  2. Use this array of Ids and make a query to the files collection and get the details for each file like thumbnail, decription and so on.

The above steps works fine, BUT I cannot keep the order from the first step thus I cannot get the most recently downloaded file on top. I know I could look trought the id array and get data for each file but that would cost me 10 queries instead of one.

  • 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-05T15:48:36+00:00Added an answer on June 5, 2026 at 3:48 pm

    I don’t really get your problem. Here’s some pseudo-code:

    // get last N download events
    events = get_latest_downloads() 
    
    // retrieve associated file data
    file_array = get_all_file_info_by_events(events)
    
    display_data = []
    for(e in events) {
      data = find_file_info_in_the_array(file_array, e.file_id)
      display_data.push(data)
    }
    
    // now display_data is contains full file info, sorted by download time.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an internal web app on our company intranet using PHP. One section
I am going to start developing a webapp using php framework codeigniter. The app
I'm developing both a Java app and J2EE webapp using Eclipse Europa on Mac
I'm developing software on google app engine. I'm using the webapp framework. is there
I am developing an web app using Codeigniter. In this app I got a
I've been developing my first web based app for about two months now (I'm
I am developing a tiny webapp on google app engine using python. I am
I'm developing a PHP web app using a MySQL database. I'm wondering what is
I am using php 5.3.3 and developing a MVC webapp using codeigniter. The code
I am developing a web app using servlets and jsps. I have a question

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.