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
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
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);
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.