Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to get local collections instance #33

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ziedmahdi
Copy link

after defining a new local collection:
var collection = new Mongo.Collection(null);

and assigning a name for it:
collection._name = collection._collection.name = 'a_name_so_i_can_get_it';

we can later retrieve it with:
var sameCollection = Mongo.Collection.get('a_name_so_i_can_get_it');

@ziedmahdi
Copy link
Author

@dburles is this package still maintained?

@dburles
Copy link
Collaborator

dburles commented Oct 24, 2016

Sorry @ziedmahdi I meant to get back to your PR. What's the reason that you've added this feature?

@ziedmahdi
Copy link
Author

So that packages like msavin:mongol and babrahams:constellation can show the content of local collections. They are using your package to get the collection instance.

When we define a local collection we pass null to the constructor.
var collection = new Mongo.Collection(null);

and like that it will be saved with no name in your arrays of instance.

CollectionExtensions.addExtension(function (name, options) {
  instances.push({
    name: name,
    instance: this,
    options: options
  });
});

and finding it will be like impossible (well if there is more then one local collection).

So, instead of only searching based on instances.$.name we can also search using instances.$.instance._name.

and after defining a local collection, you can modify it's name

var collection = new Mongo.Collection(null);
collection._name = 'a_name_so_i_can_get_it';
var sameCollection = Mongo.Collection.get('a_name_so_i_can_get_it');

Voilà!!

@dburles
Copy link
Collaborator

dburles commented Oct 25, 2016

I mean, I get that, but I'm not sure on the real world use. I gather it will be up to the user to define a name for any local collections they've created so that this package can become aware of them? That seems kind of strange given that the very idea of this package is providing the ability to gather/lookup collections without having to do anything special from the users point of view.

So I am guessing that the main reason you're adding this feature is so that your local collections can be viewed by mongol?

@ziedmahdi
Copy link
Author

For now, the only way (that I know) to give a local collection a name is to alter the _nameattribute.

For me, the main reason, was that rubaxa:sortable could not get the local collection instance that I passed. When I got it to work with rubaxa:sortable, I thought to try it with msavin:mongol and it worked. Basically, this patch will allow any package/project to pass strings instead of collection instances even for local collections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants