10

I'm in the process of evaluating MongoDB for a personal project. I'm putting together a site that will allow users to register and store information on my server.

While evaluating MongoDB I saw that it can create a database on the fly, the first time a record is inserted. That got me thinking that I could separate the data for each user into their own database. The database name will be derived from the user's unique id. After a user registers, the first time they store information their database will be created.

Does anyone know if this is a feasible design with MongoDB? Would it be better to simply store all user's data in a single database?

Community
  • 1
  • 1
Justin Kredible
  • 8,354
  • 15
  • 65
  • 91
  • Why not using the next lower level, the collections? Single databases per user seems a little bit overheaded to me. And why -in general- breaking down the user data in different stores? In most cases you separate data by type and not by ownership, wouldn't? – asaaki Dec 20 '11 at 22:25
  • MongoDB 2.2.0 introduces database-level locking. If you're storing different types of documents per user (which would have their own collections), database-per-user might be still feasible. If you're using many databases, don't forget this: http://www.mongodb.org/display/DOCS/Too+Many+Open+Files#TooManyOpenFiles-Estimatingulimitsetting – Eren Güven Oct 22 '12 at 21:30

1 Answers1

4

Yes, a single collection is better, that way you can use indexing to your advantage.

Iterating over a list of databases or collections will always take O(N) time whereas you could achieve O(log N) time to find individual documents using indexes.

Community
  • 1
  • 1
Tyler Brock
  • 29,626
  • 15
  • 79
  • 79