-1

I have 2 groups of users on my website. One is user and the other one is admin. Currently I put them in 2 different collections user and admin. My questions is:

  1. Mongodb generates _id automatically for both collections. Since they're in 2 different collections chances are one day you created one user and one admin with the same _id right? I have a table keeping track of user / admin balances so I certainly don't want the _id to collide.

  2. I can also put all users and admins in one collection. This way I don't have a problem but I am not sure if I should do this.

Any comments are greatly appreciated. Thanks!!

Community
  • 1
  • 1
Shih-Min Lee
  • 9,350
  • 7
  • 37
  • 67
  • The odds of a driver-generated duplicate `_id` are vanishingly small - you should worry more about getting struck by lightning. The decision for #2 would depend on your exact use case, but generally I'd say users are users and admins are users and you should be able to store them together and simplify your life. – wdberkeley Dec 31 '14 at 18:29

1 Answers1

1
  1. There is a very very low chance that you will have collisions.
  2. Yes, you could put users and admins in one collection and then have a 'type' attribute that differentiates regular users and admin users. I don't know your requirements or why you have them in separate collections currently, so I can't say if you should or shouldn't do it, but it sounds like it would make some things easier.
Community
  • 1
  • 1
NoOutlet
  • 1,949
  • 1
  • 14
  • 22
  • got it. about 1 it is that I am dealing with transactions and I don't want things like collide id to happen. Although I know it probably wouldn't. Also I thought when I separate the collection I can do map-reduce more efficiently on some scenarios but maybe I really shouldn't worry about this kind of things. – Shih-Min Lee Jan 01 '15 at 17:09