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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:38:43+00:00 2026-05-27T00:38:43+00:00

I am creating an API using PHP and MongoDB. In this system I got

  • 0

I am creating an API using PHP and MongoDB. In this system I got users and each user can upload files. Users can also “follow” each other.

I need to return a feed of all the latest files uploaded by users that the authenticated user is following. I am not really sure how to design and execute this.

This is what I am thinking of implementing.

  1. Get all the users that the user is following.
  2. Loop through this array of users and get latest 4 files for each user and add them to an array.
  3. Somehow order these files (this array) by creation date.
  4. Return it.

Is this really the optimal way? Is there a better way? Users are saved in the collection Users and files in the collection files. Following is saved in the collection users.followers.

  • 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-27T00:38:44+00:00Added an answer on May 27, 2026 at 12:38 am

    This is the fan-in vs. fan-out problem. I’d suggest you try fan-out:

    Keep a feed collection for your users. When a user uploads a document, insert a new feed item in each of her friends feed item collection. The collection could look like this:

    {
        "_id": (some id)
        "UserId": (id of the user who 'owns', i.e. reads this feed)
        "FriendId": (if of the friend who posted the file)
        "FriendName": "John Doe" (name of the fried, denormalized)
        "Timestamp": ...
    }
    

    Use a compound index {UserId, Timestamp}.

    This approach is write-heavy: If Jane has hundreds of friends, these hundreds of inserts will take their time. On the other hand, uploading a file generally takes a lot of time anyway, so the overhead is negligible, and your reads will be ridiculously simple.

    Of course, this can be further optimized with more effort, but it should do fine for quite a bit of traffic.

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

Sidebar

Related Questions

When creating a child process in C++ using Windows API, one can allow inheritance
I'm creating my own API for a game-statistics system (in PHP). And I want
I am developing an API using PHP (Codeigniter) and Phils RESTserver. I am creating
I am creating a facebook applicatioon using PHP-SDK and GRAPH-API. I feel like saving
Currently struggling with PHP and creating KML from it. I'm using the last.fm API
I am currently in the process of creating API documentation using Microsoft Word 2007
I'm creating a small service using api-libraries, such as Twitter. Is it possible to
I'm creating .net websites against a CMS server using the API of the software
I am creating a map using the new(ish) v3 of the Google Maps API
I am creating a scheduler using PHP/MySQL where I have to allow the use

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.