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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:34:02+00:00 2026-06-09T06:34:02+00:00

I’m doing a notification system for my website. A notification systeme like facebook .

  • 0

I’m doing a notification system for my website.
A notification systeme like facebook. Or stackoverflow.
I have 2 problems.

  1. How store in db ? I can store ALL notifications in the user document ? or in a document apart (because i think monogdb is limited for size in a document ?) Or, store intelligently ? (using inc, or a value (see: true/false) in db, with query sophisticated)

  2. How do for brought at the page ? For exemple, when i click in a link in my inbox for stackoverflow, i’m redirect to the page. But me, i have a system that is multipage for exemple: I have 100 friends. There are listed 30 per page. So when i click on the notification i can’t redirect to the because it’s impossible to know the good page (users can be removed).

Thank you very much !
And if you have another ideas, tell me. Thanks.

EDIT:

(sorry for my english, i’m french)

For the first problem, i realize that i have to wait the time comes to choose my structure. Because my notification is .. a little complicated, so advance to the feeling.

For the second, i solved the problem. I explain:
(I take the exemple of friends because it’s easy to undestand.)
I stored my data like this:

{
  friends: [
    {_id: xxxxx, ts: xxxx},
    {_id: xxxxx, ts: xxxx}
  ]
}

Imagine i display all friends: 30 per page.
The problems are:

  • when i want to display all friends i cant sort using mongo. (a little problem)
  • If i want to lead a user to this list (30 per page) at a special friend, always keeping the sort by ts. I can’t know the page. The uniq solution is to take all document.
    But: veryyy bad in performance.

So, i store like this:

{
  friends: {
    xxxx: {ts:xxx},
    xxxx: {ts:xxx}
  }
}

Know i can sort the document, with use skip and limit.
So if i want a portion, i do not need to take all documents.

To know the page, i just do the number of < or > to the ts, i have for exemple 11 friends who are > to the ts of the friends that i want, and do a count for all friends (ex: 50 friends) with 50 and 11, i can guess the page.

Is this solution is good ?
– i need a count
– a query to know the number of > or <
and i can take the page where is listed the friend, keeping the sort ts

You can don’t understand why i use a count. I need because they are not store in the same docment.

2 EDIT:

The problem with this solution, is that i need to make query object and update object outside of the mongo query (ex: for do friends.xxxxxx: {$exists:true}

ps: And what advantages are to use ts instead of date for mongodb ?
I’m using ts but i think i will store date, and no ts.

3 EDIT

I will do like Sammaye. Store in separate document. Take a look at: http://mongly.com/Multiple-Collections-Versus-Embedded-Documents/#1 and http://openmymind.net/2012/1/30/MongoDB-Embedded-Documents-vs-Multiple-Collections/

  • 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-09T06:34:04+00:00Added an answer on June 9, 2026 at 6:34 am

    @Stennie make a pretty complete answer.

    However recently I did a similar thing in PHP for my website. The first thing to understand is whether you are doing a notification system or a wall (the two are very different), it seems unclear to me and I am not sure what you mean by:

    How do for brought at the page ? For exemple, when i click in a link
    in my inbox for stackoverflow, i’m redirect to the page. But me, i
    have a system that is multipage for exemple: I have 100 friends. There
    are listed 30 per page. So when i click on the notification i can’t
    redirect to the because it’s impossible to know the good page (users
    can be removed).

    That is not very good English and is very confusing when I read it. If you can expand on that I am sure people can answer better.

    For a notification system I found that a large collection of notification objects also worked. So I had a schema like:

    {
        _id: {},
        to_user: ObjectId{},
        user_id: ObjectId{}, // Originating user
        custom_text: "has posted a new comment on your wall post",
        read: false,
        ts: MongoDate()
    }
    

    And this would literally be the document I have to produce notifications. Each time a user commits an action that generates a notification it writes a new row to the DB with to_user being populated each time with each user needing to be notified. As for multiple users commiting the same action I actually convert the user_id field in a list of OjbectId‘s so I can say:

    Sam, Dan and Mike all commented on your wall post

    I then query by ts storing the last ts that the user looked at in their row allowing me to do a range based query on the newest notifications each time. This works quite well for sharding and querying in my personal experience.

    Hope it helps,

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
I have a text area in my form which accepts all possible characters from
I have some data like this: 1 2 3 4 5 9 2 6
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small

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.