1

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.

Burak
  • 5,706
  • 20
  • 70
  • 110
  • Are you after a commutative relationship? ie. is it a "follow" system à la Twitter, where it's not necessarily mutual, or a "friend" relationship à la Facebook, where the request needs to be accepted? – Brenton Alker Dec 11 '12 at 16:56
  • Follow system, no need to request. – Burak Dec 11 '12 at 16:58

2 Answers2

1

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.

Sam Holder
  • 32,535
  • 13
  • 101
  • 181
  • Yes, I just holding the user ids on each user. What if I need the details? I guess I should do request for user details for followers like /users/:userid/followers – Burak Dec 13 '12 at 07:02
  • That looks like a sensible restful Url to me Barak. Post to that url to add followers. – Sam Holder Dec 16 '12 at 22:30
1

What all operations you want to do with that?

you may want to check Twitter-like app using MongoDB

Community
  • 1
  • 1
Raxit Sheth
  • 2,491
  • 5
  • 17
  • 20