MeteorCommunity / discussions

Track technical discussions in the Meteor community
89 stars 7 forks source link

How to get collection from a string "name" #2

Open raix opened 9 years ago

raix commented 9 years ago

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?

Eg.

  // Client + Server
  var myTestCollection = Mongo.Collections.lookup('test');
dandv commented 9 years ago

autocomplete uses golbal[collectionName]

There's also this SO question - http://stackoverflow.com/questions/10984030/get-meteor-collection-by-name

awatson1978 commented 9 years ago

I've been preparing to do an extended collections API, because of the getTimestamp() issues; as well as exposing db.stats() and db.serverStatus(). I'd be more than happy to add .lookup(). Although ETA is probably 3 months off still.

https://github.com/awatson1978/collection-extended-api/blob/master/README.md

mitar commented 9 years ago

I have some extensions to the API in directcollection package. One thing I am missing (from Django) is .exists() query, which would make an optimized query and tell you if the query matches any document. Doing .count() instead is very bad because you do not really need/want precise number (and counting a precise number is not very cheap in MongoDB).

mitar commented 9 years ago

Related: https://github.com/meteor/meteor/issues/1504

dandv commented 9 years ago

In the meantime I've used in rubaxa:sortable and improved @dburles' mongo-collection-instances

mitar commented 8 years ago

I think this pull request which was recently merged could help a bit: https://github.com/meteor/meteor/pull/5845