Hey guys,

im working on a website and i need to design the database so that a user can follow another user and it will be easy to figure out the number of people i follow and the number of followers i have.

I'm using mongoDb btw. http://www.mongodb.org/

can someone please provide an explenation on how i can achieve this by using a NoSql database such as the one i listed?

Thank you

6 Years
Discussion Span
Last Post by diafol

Could you say why you're using a NoSQL?


I'm using nosql because its easier to setup, easier to work with, and performs faster.


Does anybody have an idea of how to design the database structure so a user can follow another user and i can see who follows me and also so i can see who i follow?



follow_id (PK, optional field)
user_id (FK)
follower_id (FK, also user id)
datefollowed (datefield, optional)

Like that?

You select on user_id = yourself to see the number and flavour of followers. You search follower_id = yourself to see who you're following.

SO, is your DB huge? Curious about NoSQL as well.


At the moment, the database is not huge, just in development at the moment. However, i anticipate that this collection (table) will be large, since people following people will get rather large rather quickly.

NoSql in the case of MongoDb is pretty sweet though, i can store my blogs comments inside my blog record in an embedded document called comments - additionally i can store replies to the comment in the comment itself in arrays, or embedded documents.

You don't need to do any pre-configuring of the database, when you add a document to a collection, if the collection doesnt exist it will create it, as well as any fields that you choose to insert with it also.


Interesting, I had a look at NoSQL, but didn't see the point. Perhaps I'll give it another look. :) Thanks.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.