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

Maybe add the ability to give names to the local collections? #31

Open
ivansglazunov opened this issue Mar 9, 2016 · 27 comments
Open

Comments

@ivansglazunov
Copy link

abc = new Mongo.Collection(null, { localName: 'abc' });
Mongo.Collection.getLocal('abc'); // 1
Mongo.Collection.get(null, { localName: 'abc' }); // 2
Mongo.Collection.get('abc'); // 3

Perhaps it would be necessary to add this capability. I doubt in the interface. Which of these options is more like it? How the best option to name? localName somehow ugly.

@ivansglazunov
Copy link
Author

I have the package shuttler:ref where it would be very useful.

@dburles
Copy link
Collaborator

dburles commented Mar 9, 2016

Yeah that's a bit tricky, I'm not entirely sure of the potential use cases (we haven't had any issues crop up relating to looking up null collections so far)

@ivansglazunov
Copy link
Author

so far I have 2 options:

  • I will make a package ivansglazunov:mongo-collection-instances-null as wrapper with 3 option and name field.
  • I will make pull request if you approve option

@dburles
Copy link
Collaborator

dburles commented Mar 9, 2016

Potentially we could allow extra naming feature for both null and named collections, this may make handling multiple connections a lot more intuitive

@dburles
Copy link
Collaborator

dburles commented Mar 9, 2016

Rather than passing in the connection, we can instead reference the name

@ivansglazunov
Copy link
Author

If you specified an alternate name in the options, the main will be used?

@dburles
Copy link
Collaborator

dburles commented Mar 9, 2016

Foo1 = new Mongo.Collection('foo', { ref: 'foo1' });
Foo2 = new Mongo.Collection('foo', { ref: 'foo2', connection: ... });

// if a 'ref' is passed in, we use that name rather than 'foo'
Mongo.Collection.get('foo1');
Mongo.Collection.get('foo2');

@dburles
Copy link
Collaborator

dburles commented Mar 9, 2016

I think in that case, if you define null collections without a reference, we just ignore them

@ivansglazunov
Copy link
Author

Mongo.Collection.get('foo'); // too ?

@ivansglazunov
Copy link
Author

Should not be ignored. For example, we use custom adapter instead of DDP.

@dburles
Copy link
Collaborator

dburles commented Mar 9, 2016

I don't think that'd be possible due to the name clash

@dburles
Copy link
Collaborator

dburles commented Mar 9, 2016

Do you mean another connection?

@ivansglazunov
Copy link
Author

Yes.

new Mongo.Collection(null, { connection: ourCustomDB });
Mongo.Collection.get(null, { connection: ourCustomDB });

@dburles
Copy link
Collaborator

dburles commented Mar 9, 2016

In that case you would also provide a ref on instantiation just like above. Will that not work in your case?

@ivansglazunov
Copy link
Author

Yes, it was cool. Only then it is not clear for what we need the second argument of the get

@dburles
Copy link
Collaborator

dburles commented Mar 9, 2016

Hmm, can you confirm that arbitrary options make it through to addExtension?

@dburles
Copy link
Collaborator

dburles commented Mar 9, 2016

I think it should be alright, you will specify the ref option for null collections, as well as any collections that are on a different connection. Perhaps Mongo.Collection.getRef('...') is better?

@dburles
Copy link
Collaborator

dburles commented Mar 9, 2016

That will solve this outstanding issue: #22

@ivansglazunov
Copy link
Author

get => getAll
getRef...
Not very much.
I liked the .get(name/ref: String)

@dburles
Copy link
Collaborator

dburles commented Mar 10, 2016

Though it would be possible to overwrite a ref if we later define a collection with the same name which may be confusing?. The advantage of using getRefmeans the two are distinct.

@ivansglazunov
Copy link
Author

It is a question of validation and comparison of patterns.
Name conflicts can not escape. If the owner of the application knows which makes, then it is a true owner of the app :)

@ivansglazunov
Copy link
Author

Exit - namespace tree :) And I think this is not the exit.

@dburles
Copy link
Collaborator

dburles commented Mar 10, 2016

Let's go with just get, happy for you to continue with the PR along with some tests for the new functionality

@ivansglazunov
Copy link
Author

I think for backward compatibility should leave collection.

@dburles
Copy link
Collaborator

dburles commented Mar 10, 2016

I agree, though it's not entirely working, see here: #22

@ivansglazunov
Copy link
Author

May be because connection must be an object with _lastSessionId field?

@dburles
Copy link
Collaborator

dburles commented Mar 10, 2016

Possibly. Let's continue discussion on the PR.

@dburles dburles mentioned this issue Mar 10, 2016
1 task
ivansglazunov added a commit to ivansglazunov/mongo-collection-instances that referenced this issue Mar 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants