2

So I have a basic structure (similar to an app for chat rooms) where:

  • Multiple "rooms" are created dynamically
  • Each room has two subgroups, one for Users and one for the actual info (the messages, let's say)
  • Both subgroups are structured as Collections (Meteor.users is naturally structured that way, and right now I'm testing with just one room and it's a separate Collection on my database)

My question is, is it more efficient to make one Collection with multiple rooms as its entries, or should I just make a new Collection for each room?

I'm planning to use something like the Partitioner package to assign different groups of users to their correct rooms, assuming the Meteor.users Collection can't be moved around.

parodyse
  • 111
  • 1
  • 3

1 Answers1

1

Short answer

Use a single collection for all of your rooms. Each room should be a separate document in that collection.

Long answer

I have yet to hear a use case where creating dynamic collections was a reasonable solution. Furthermore, I'm not convinced that it's even possible to create dynamic collections in meteor because both the server and all of the connected clients need to know about the new collection - see this attempt. It's a giant rathole that isn't worth exploring.

Community
  • 1
  • 1
David Weldon
  • 63,632
  • 11
  • 148
  • 146
  • Also, [modifying more than one document in arbitrary collections](https://github.com/meteor/meteor/issues/3271) exposes the server to security risks, because it must provide to the client a Meteor method that takes the collection as a parameter, and that parameter can be set by an attacker to any collection. Alternatively, the client would be forced to modify only one record at a time and incur the performance penalty. – Dan Dascalescu Jan 31 '15 at 21:52