Best MongoDB schema for twitter clone?

I know similar questions have been asked, but looking for a very basic answer to a basic question. I am new to MongoDB and making a twitter style app (blogs, followers, etc) and I’m wondering the best schema to use.

Right now I have (on a very high level):

  • Using Webpack with Mongoose - mongoose.model is not a function
  • Connecting to MongoDB deployment using SSL and mongos through Mongoose.js
  • Updating a subfield in a mongoDB document using findOne and save
  • How To Require A Model Within Another Model's Schema When It Hasn't Been Registered Yet
  • cannot get PUT to work on Nodejs / express
  • mongodb/mongoose findMany - find all documents with IDs listed in array
  • Member {
      login: string,
      pass: string,
      posts: [
          title: string,
          blog: string,
          comments: [ { comment: string } ]

    There is more to it, but that gives you the idea. Now the problem is I’m looking to add the “follow” feature and I’m not sure the best route to go.

    I could add a “following” embedded doc to the Member, but I’m just not sure using mongoDB what the smartest method would be. My main concearn would obviously be the main “feed” page where you see all of the people you are following’s posts.

  • Show a list of users logged in, (passportjs, sessions, maybe sockets)?
  • How to get update confirmation in mongodb nodejs driver?
  • Error while deploying Node.js App to Heroku
  • add like/dislike to answer which is an ObjectId to a questionSchema.
  • Passport.js and Mongoose.js populate User on login - loses populated field on req.user
  • Return results mongoose in find query to a variable
  • 3 Solutions collect form web for “Best MongoDB schema for twitter clone?”

    This is not an ideal schema for a Twitter clone. The main problem is that “posts” is an evergrowing array which means mongo will have to move your massive document every few posts because it ran out of document padding. Additionally there’s a hard (16mb) size limit to documents which makes this schema restrictive at best.

    The ideal schema depends on whether or not you expect Twitter’s load. The “perfect” mongodb schema in terms of maintainability and easy of use is not the same as the one I’d use for something with Twitter’s throughput. For example, in the former case I’d use a posts collection with a document per post. In the high throughput scenario I’d start making bucket documents for small groups of posts (say, one per “get more” page). Additionally in the high throughput scenario you’d have to keep the follower’s timeline up to date in seperate user timeline documents while in low throughput scenarios you can simply query them.

    This question is the same the one how widely used in the blog post example and how to model blog posts and comments. You just have to apply the same concepts here. You have the following options:

    • embedded documents
    • dedicated collections and performing multiple queries

    The pros and cons have been widely discussed. Embedded docs can only be 16MB large and it is not possible to return individual parts of an matched array in MongoDB…make your choice.

    Not going any further because as said: the same question has been discussed in numerous questions about “schema design”. Just google “Schema Design MongoDB” or look for the same on SO.

    Adding a “following” array to the Member document should work well. It should contain the user IDs of the people that member is following. Your code will have to retrieve the list and construct a query that retrieves the tweets of those users. As Mongo is nonrelational, there’s no way to construct a query that joins the Member and Tweet collections and does this in a single query, but you should be able to reduce network overhead by doing this on the database server, using server-side code execution:

    Node.js is the Best Javascript runtime in the world.