Reputation: 5764
I want to use MongoDB and Node.js in my project. What I need is, modelling the db for friendship relationships(User1 follow User2). Ina relational DB it is easy, but I dont know how to do this with MongoDB. I will also use REST API so I should be able to make relationships via REST api
Edit:
Is it a good way?
following: [[{ type: Schema.Types.ObjectId, ref: 'User' }]]
If I do that, should I save both follower and followed? I am getting too many recursion error.
Upvotes: 1
Views: 2419
Reputation: 2601
What all operations you want to do with that?
you may want to check Twitter-like app using MongoDB
Upvotes: 1
Reputation: 32946
can you not just maintain a list of FollowedBy and Following user ids on each user and just update those lists whenever new relationships are added?
Effectively you are denormalising that data due to lack of relational support.
Upvotes: 1