FR/PR: How to get collection from a string "name"

1,024 views
Skip to first unread message

Morten Henriksen

unread,
Jan 1, 2014, 3:48:51 PM1/1/14
to meteo...@googlegroups.com
I often find my self in having to wrap the Meteor.Collection in order to get a lookup option. I may have the collection name but currently there isnt a way to resolve the string into a collection?

Would you take a pull request on this feature?

I would simply add a "getter" in collection.js about ln 90 (in the registerStore object)

eg.:

collection: function() {
  return self;
}

To make the lookup later:
// getting the "foo" collection
myFooCollection = Meteor.connection._stores['foo'].collection();

Kind regards Morten

David Glasser

unread,
Jan 3, 2014, 8:38:18 PM1/3/14
to meteo...@googlegroups.com
This would be client side only?
> --
> You received this message because you are subscribed to the Google Groups
> "meteor-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to meteor-core...@googlegroups.com.
> To post to this group, send email to meteo...@googlegroups.com.
> Visit this group at http://groups.google.com/group/meteor-core.
> For more options, visit https://groups.google.com/groups/opt_out.

Morten Henriksen

unread,
Jan 4, 2014, 8:04:09 AM1/4/14
to meteo...@googlegroups.com
I see...

I guess it possible to use same collection name on two/more different connections ddp/mongo etc.

It would have been nice to have something like Meteor.getCollection on both client and server to lookup collections

Meteor.getCollection('foo', { connection: bar })

if no option connection is passed in default to:
  • Meteor.connection._mongo_livedata_collections (client)
  • MongoInternals.mongo._getCollection(name) (server) ?

Andrew Mao

unread,
Mar 12, 2014, 2:54:34 PM3/12/14
to meteo...@googlegroups.com
I'm looking for something like this as well, for packages like https://github.com/mizzao/meteor-autocomplete that work with arbitrary user collections.

However, MongoInternals.defaultRemoteCollectionDriver().mongo._getCollection("foo") currently returns the underlying mongo collection, not the corresponding Meteor.Collection on the server. I am currently looking for where these objects are at the moment and can't for the life of me figure out where they are being stored.

Morten Henriksen

unread,
Mar 13, 2014, 12:09:28 AM3/13/14
to meteo...@googlegroups.com
On the client or server?

Sendt fra min iPad
You received this message because you are subscribed to a topic in the Google Groups "meteor-core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/meteor-core/1va0hjd1Wes/unsubscribe.
To unsubscribe from this group and all its topics, send an email to meteor-core...@googlegroups.com.

To post to this group, send email to meteo...@googlegroups.com.
Visit this group at http://groups.google.com/group/meteor-core.
For more options, visit https://groups.google.com/d/optout.

Slava Kim

unread,
Mar 20, 2014, 8:42:30 PM3/20/14
to meteo...@googlegroups.com
Andrew's answer was about server side. On the client there is an underscore property of the DDP connection: Meteor.connection._mongo_livedata_collections

Andrew Mao

unread,
Mar 21, 2014, 1:10:24 AM3/21/14
to meteo...@googlegroups.com
Slava: my answer there still wasn't the `Meteor.Collection`, it is the underlying mongo driver's collection. Is there even a way to get the Meteor.Collection instance from its name? I know it is stored somewhere, because if you try multiple times it says "there is already a collection named ..."

Morten Henriksen

unread,
Mar 21, 2014, 1:46:22 AM3/21/14
to meteo...@googlegroups.com
Thanks slava, i know about the code, its discussed prior in this thread, i guess gg is hiding information all the time, imho i Think its a great tool for tracking feature requests and motivating community contributions.

Sendt fra min iPhone

Gwendall Esnault

unread,
Oct 12, 2014, 4:52:25 PM10/12/14
to meteo...@googlegroups.com
Any news about that? Still can't find where collections instances are accessible server-side. 

David Burles

unread,
Oct 13, 2014, 10:48:50 AM10/13/14
to meteo...@googlegroups.com

Rom

unread,
Jan 26, 2015, 2:28:56 PM1/26/15
to meteo...@googlegroups.com
Any better way to do that today?
Reply all
Reply to author
Forward
0 new messages