Reputation: 2811
I have a mongo database with the with a users collection and a followers collection. The Users collection stores a name, username and profile_pic file location in Amazon s3. The Followers collection stores the users_id and information of the followee(person their following) including their _id, username, and profile_pic file. While the _id and profile_pic will never change, the username can if users chooses to. Therefore, the document wouldn't be updated with the most current username. This isn't a problem in mysql because its relational. Being new to Mongodb, how do people solve this sort of issue? If I need to get all 300 of a users friends or more it doesn't seem reasonable to me make 300 calls to get the individual username. Any help is much appreciate. Thanks!
Upvotes: 0
Views: 43
Reputation: 651
I think you can store user profile and followers in one users collection like this:
{
_id: 'T4Y...AC', // base64-encoded ObjectId
name: 'Rick',
profile: { ... username, profile_pic , etc. ... },
followers: ["T4Y...AD", "T4Y...AF", "T4Y...AI"]
}
Upvotes: 2