Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Namespaced Collections in Meteor

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!

like image 610
pmuens Avatar asked Nov 02 '22 02:11

pmuens


1 Answers

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.

like image 131
Kelly Copley Avatar answered Nov 10 '22 15:11

Kelly Copley