3

I'd like to use MongoDB to store my users location history (with their consent, of course). I see the following three options:

  1. Create one locations collection for all users. Each document would have a userId field, as well as a time field, both of which would be indexed. The number of rows in this collection could potentially grow beyond 100 million.
  2. Create one collection with users which have their locations as embedded array. That makes searching for locations a little more difficult, since MongoDB apparently doesn't support queries which return embedded documents.
  3. Create one collection per user with his/her location history. I'm aware of the limit of 24K collections for one MongoDB instance and I think that limit is tolerable for now.

I'd appreciate any feedback which helps me making the choice.

Thanks and cheers, Georg

BumbleGee
  • 2,031
  • 3
  • 18
  • 18
  • it really depends on what you're looking for-- what are you going to be querying on? if a user has been to a specific location, or if a location is frequented by many users? if you choose schema #1, you can index on userId and location_id, and for #2, if you're expecting location_id to steadily increase for each user, that will come at a cost to performance. – Barrie Feb 23 '12 at 22:21
  • Thanks Barrie. It is not really clear at this moment what kind of queries I'm going to need. It's an exploratory project. I think it is likely though, that I will implement some features which will involve finding nearest friends. That's why my favorite is option 1, at the moment. – BumbleGee Feb 23 '12 at 22:25
  • As it should be. It's the only option that offers flexibility without imposing limitations on scaling up to more than 24k users. Go for 1. – Remon van Vliet Feb 24 '12 at 09:22

1 Answers1

3

As mentioned in the comments above, I've chosen option 1 and have no regrets at this point. Thanks for your help.

Cheers, Georg

BumbleGee
  • 2,031
  • 3
  • 18
  • 18