title: Building a simple news feed in node + Mongodb + Redis
body: <p>My goal is to build a simple news feed in node.js with the help of mongodb and redis. It similar like twitter</p>
  
  <p>So the scenario is pretty straight forward, once User A follow User B. Later on User's A News feed (Home page) will be shown User B's Activity like what he posted.</p>
  
  <p>Schema for User</p>
  
  <pre><code>const UserSchema = new Schema({
    email: { type: String, unique: true, lowercase: true},
  });
  
  
  
  const followSchema = new Schema(
      {
          user: { type: Schema.Types.ObjectId, required: true, ref: 'User' },
          target: { type: Schema.Types.ObjectId, required: true, ref: 'User' },
      });
  </code></pre>
  
  <p>Currently the design of my user's schema is pretty simple, when I follow another user, I will just create the Follow Schema Object</p>
  
  <p>and there is another schema, which is post schema</p>
  
  <pre><code>/* This is similar like the Tweet */
  var PostSchema = new Schema({
    // Own by the user
    creator: { type: Schema.Types.ObjectId, ref: 'User' }
    body: String,
  });
  </code></pre>
  
  <p>This schema is for user to post anything, similar like twitter posting.</p>
  
  <p>Let say I have followed bunch of users</p>
  
  <pre><code>{
     user: 'me',
     target: 'draco'
  },
  
  {
    user: 'me',
    target: 'donald'
  },
  
  {
    user: 'me',
    target: 'joker'
  }
  </code></pre>
  
  <p>and let say one of my followers, post something. How do i present it to my current news feed?</p>
  
  <pre><code>/* I'm following Joker */
  app.post('/follow', (req, res, next) =&gt; {
     let follow = new Follow();
     follow.user = "me";
     follow.target = "joker";
     // Do i need to use redis to subscribe to him?
     follow.save();
  })
  
  
  /* Joker posted something */
  app.post('/tweet',(req, res, next) =&gt; {
     let post = new Post();
     post.creator = "joker";
     post.body = "Hello my name is joker"
     post.save();
     // Do i need to publish it using redis so that I will get his activity?
  
  });
  </code></pre>
  
  <p>Here's my attempt</p>
  
  <pre><code>app.get('/feed', function(req, res, next) {
  
       // Where is the redis part?
       User.findOne({ _id: req.user._id }, function(err, foundUser) {
          // this is pretty much my attempt :(
       })
  })
  </code></pre>
  
  <p>When should I use redis to actually do the pub and sub? so that I could take the content of one of my followers and show it on my timeline?</p>