Meteor-Community-Packages / mongo-collection-instances

🗂 Meteor package allowing Mongo Collection instance lookup by collection name

Home Page:http://packosphere.com/dburles/mongo-collection-instances

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This feature was added to Meteor Feb 2016

malhal opened this issue · comments

As of Feb 2016 it is now possible to look up an existing collection, finally!!!

meteor/meteor#5845 (initial attempt)
meteor/meteor#6160 (fix)

Works like this:

Meteor.connection._stores['tasks']._getCollection()

Hey @malhal thanks for letting me know, strange that no one mentioned it to me earlier

So now we know they added it as a private API so that you could make use of it in your public API...will you be using it? 😉

Yep, I'll try to update it sometime this week, though it looks like it won't be backwards compatible.

Maybe there is a way to implement it differently depending on Meteor's version number?

api.versionsFrom should take care of that. I'll also publish this current version as 1.0 (I should have done that a while back) then I'll release the newer one as 2.0.

Nice! By the way I should mention so far I've only used this on the client so not sure about the server.

Update: doesn't appear to work on the server:

TypeError: Cannot read property '_stores' of undefined

Hmm maybe there is more to this than we thought.

Hmm, would you mind finding out if that's the case back over on the PR?

For the server you can get them like:

Package['mongo].MongoInternals.defaultRemoteCollectionDriver().open('colName')

as in with import / export:

import { MongoInternals } from 'meteor/mongo'

MongoInternals.defaultRemoteCollectionDriver().open('colName')

Good, Now I found it 💯

@StorytellerCZ I vaguely remember looking into this, granted it was over 5 years ago. I recall though that it wasn't ideal as there was no way to get collections across different connections, unlike the way this package currently works. Though there still might be a potential enhancement here.

That is my conclusion as well. I will look into this in the future.