Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB schema for storing user location history

Tags:

mongodb

schema

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

like image 243
BumbleGee Avatar asked Dec 20 '25 18:12

BumbleGee


1 Answers

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

Cheers, Georg

like image 64
BumbleGee Avatar answered Dec 22 '25 11:12

BumbleGee



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!