mongo-collection-instances icon indicating copy to clipboard operation
mongo-collection-instances copied to clipboard

This feature was added to Meteor Feb 2016

Open malhal opened this issue 9 years ago • 12 comments
trafficstars

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

https://github.com/meteor/meteor/pull/5845 (initial attempt) https://github.com/meteor/meteor/pull/6160 (fix)

Works like this:

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

malhal avatar Jun 21 '16 08:06 malhal

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

dburles avatar Jun 21 '16 10:06 dburles

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? 😉

malhal avatar Jun 22 '16 12:06 malhal

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

dburles avatar Jun 22 '16 12:06 dburles

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

malhal avatar Jun 22 '16 12:06 malhal

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.

dburles avatar Jun 22 '16 13:06 dburles

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.

malhal avatar Jun 22 '16 13:06 malhal

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

dburles avatar Jun 23 '16 08:06 dburles

For the server you can get them like:

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

fakenickels avatar Aug 13 '16 00:08 fakenickels

as in with import / export:

import { MongoInternals } from 'meteor/mongo'

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

matteodem avatar Nov 08 '16 08:11 matteodem

Good, Now I found it 💯

thearabbit avatar Feb 18 '18 15:02 thearabbit

@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.

dburles avatar Feb 14 '22 09:02 dburles

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

StorytellerCZ avatar Feb 14 '22 09:02 StorytellerCZ