2

I am new to MongoDB. I have designed a app with a follower/following like Twitter style

My schema is as follows

UserSchema :

    username:'Alex',
    pass:'salted',
    likes:'200'

FollowSchema

    uid : {
        type: Schema.ObjectId,
        ref: 'User'
    },
    fid : {
        type: Schema.ObjectId,
        ref: 'User'
    }

First of all, is this a scalable design ?

If so, I would like to get all the users except logged in user and find if each user is following the logged in user or not.

I am thinking of Aggregation or mapreduce but not sure how to approach.Any help is appreciated.

Thx

2 Answers 2

2

Yes this looks like a good way to do it, according to this post here:

mongo db design of following and feeds, where should I embed?

as well as the mongodb website:

http://blog.mongodb.org/post/61499097398/tracking-twitter-followers-with-mongodb

Sign up to request clarification or add additional context in comments.

Comments

1

In mongodb there is no join operation. In mongoose you can use populate().

http://mongoosejs.com/docs/populate.html

Follow.find({}).populate('uid').populate('fid').exec(function (e, d) {
   if(e){
      res.json(e);
   }
   else {
      res.json(d);
   }
});

1 Comment

Thanks...But how do I get all the users first and then find if a specific user is following the logged in users.As per your code, unless the user is in the follow document,I would not get the user details in results.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.