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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:52:56+00:00 2026-05-28T17:52:56+00:00

I use MongoDB + PHP for a facebookish newsfeed with different kinds of feeds

  • 0

I use MongoDB + PHP for a “facebookish” newsfeed with different kinds of feeds (post, photo, poll, etc.) and with comments.

Each feed belongs to some “channel” – currently it could be user or group (there may be more containers in future).

Any user can subscribe for any channel or unsibscribe from it.

Now let’s say there’re tons of channels and tons of feeds. What is the best structure for channels/feeds/comments?

I’m thinking about two approaches:

1) Feeds collection with list of subscribers in each feed:

feeds: 
[
   {date_added: ..., 
    last_update: ..., 
    title: ...,
    text: ...,
    channel: ..., 
    channel_subscribers: [...],
    comments_subscribers: [...],
    comments: [...] 

   },
   {...},
   {...},
   {...}
]

If I want to get last feeds:

db.feeds.find({date_added: "this week", channel_subscribers: "my_login"});

If I want to get feeds with new comments:

db.feeds.find({last_update: "this week", comments_subscribers: "my_login"});

Pros:

  • Simple and fast readings?

Cons:

  • When I want to subscribe/unsibscribe for/from a channel, I have to run
    trough all feeds and push/pull my name from list of
    channel_subscribers; it could be slow if I have tons of feeds

2) Separate “channels” collection:
Same thing but keep list of subscribers in channel collection:

channels: 
[
  {channel_id:..., last_update: ..., subscribers: [...]},
  {channel_id:..., last_update: ..., subscribers: [...]}
]

First I have to query last updated channels:

subscribes = db.channels.find({last_update: "today", subscribers: "my_login"})

Now find my feeds:

db.feeds.find({channel: {$in: subscribes}], date_added: "today"})

Pros:

  • Simple, fast and more safe subscribing/unsubsribing;

Cons:

  • I feel I should avoid $in because it’s slow(?), especially when I have lots of
    subscribes to put inside of this operator.

3) Keep user subscribes in users collection (so each user has an array of his own subscribes)

users:
[
  {_id: ..., login: ..., email: ..., subscribes: [...]}
]

Cons:
– in this case we’ll have even bigger array to put inside of $in than in previous (#2) approach.

4) Your suggestions?

  • 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-28T17:52:57+00:00Added an answer on May 28, 2026 at 5:52 pm

    OK I’ll answer by myself. I tried to make a test on my laptop Windows 7 32 bit / 2GB RAM.
    I created a “feeds” collection and filled it with 500 feeds:

    feeds:
    [
     {_id: ..., subscribers: [...]},
     {_id: ..., subscribers: [...]},
    ]
    

    Each “subscribers” array have a list of 2000 short random string names.

    First I have to mention that my DB increased in size from 60Mb to 1.5Gb.

    Then when I run a shell command db.feeds.ensureIndex({subscribers: 1}) it hanged for ~3 minutes and then stopped with error: "can't map file memory - mongo requires 64 bit build for larger datasets".

    So it’s definately not a good idea to create such large multikey fields inside of mongo’s documents.

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

Sidebar

Related Questions

I'm trying to use mongodb with PHP. For that, I have created a MongoHQ
I'm attempting to use the new mongodb aggregation framework from php. I'm using mongod
I use Doctrine 2 ODM\MongoDB (this and dependencies all latest from GIT) + PHP
Can I use MongoDB and a PostgreSQL in one rails app? Specifically I will
I am starting to use mongodb for data storage. In mysql I save a
i'm trying to use mongodb as a network wide configuration storage. This the same
I have a good reason to use MongoDB for part of my app. But
Is it a good idea to use MongoDB in .NET desktop application?
I edited the app.py file to only use MongoDB through MongoEngine(you get to choose
I want to allow my shared hosting sites to use MongoDB, however as they

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.