5

I'm currently developing a Meteor application which will be based on different packages (maybe created by different developers).

My question is if there's a meteor'ish way to namespace collections so that they won't collide with other available collections.

For example, I have a package which uses the collection with the name 'todos' and another one which may also include a collection with the name 'todos'. Is there a way to namespace these collections (e.g. with their package-Name prepended)?

I've found out that there's an option for namespacing in MongoDB with a '.': http://docs.mongodb.org/manual/faq/developers/#what-is-a-namespace-in-mongodb

Is this also the best way to namespace collections in Meteor?

Coming to Meteor with a Rails background, I can remember that you can create namespaced Engines in rails (which also creates namespaced database-Tables). Is there something similar in Meteor?

The closest I came was with this Issue I've found: https://github.com/CollectionFS/Meteor-cfs-gridfs/issues/6

Thanks in advance!

pmuens
  • 788
  • 6
  • 16
  • 1
    As far as my knowledge goes MongoDB doesn't allow you to create namespaced collections (except for databases) and so doesn't Meteor. – imslavko Apr 06 '14 at 23:26
  • Unless you want to namespace them manually in the string name (ex.: "bobbyApp_questions" and "aliceApp_questions" - no access separation or anything) – imslavko Apr 06 '14 at 23:27
  • So use separate databases if it is appropriate. – imslavko Apr 06 '14 at 23:27
  • 1
    This package https://atmospherejs.com/package/dbproxy might help. – Serkan Durusoy Apr 07 '14 at 22:52
  • Thank you for your comments! I think I'll stick with the prepending of the namespace to the collection-Name (such as 'fooCollection' or 'foo_collection') – pmuens Apr 08 '14 at 17:42

1 Answers1

2

Using a period in the collection name is a perfectly fine namespacing scheme for Meteor collections just as it is if you were using MongoDB alone.

var TodoCollection = Meteor.Collection('packageName.todos');

Packages such as CollectionFS use this technique to avoid collection name collisions.

Kelly Copley
  • 2,990
  • 19
  • 25
  • Thank you! Beforehand I've used things such as Meteor.Collection('fooBarBaz');. The dot-Notation made it much clearer and it also feels better. – pmuens Apr 30 '14 at 08:27