-
-
Notifications
You must be signed in to change notification settings - Fork 169
Collection Instances
While FilesCollection has a direct reference to a Mongo.Collection
,
the Mongo.Collection
has a back-reference to the FilesCollection itself.
The reference chain is as the following:
const Images = new FilesCollection({collectionName: 'Images'});
// get the underlying Mongo.Collection
const collection = Images.collection;
// get the 'parent' FilesCollection
// of this collection instance
const parent = collection.filesCollection;
// returns true
console.log(parent === Images);
In Meteor for Mongo.Collection
instances management, we suggest to use dburles:mongo-collection-instances.
It allows to retrieve Mongo.Collection
instances by its name in any module or file.
Note: This package comes with no dependency to dburles:mongo-collection-instances
.
To make use of it, install it to your Meteor project first.
meteor add dburles:mongo-collection-instances
Then initialize FilesCollection, which itself will create a new Mongo.Collection
, that is automatically added to a hidden Mongo.Collection
instances list.
const Images = new FilesCollection({collectionName: 'Images'});
To retrieve FilesCollection use - Mongo.Collection.get('collectionName')
:
const ImagesCollection = Mongo.Collection.get('Images');
const Images = ImagesCollection.filesCollection;
This simplified example shows, how to make use of that technique in your own implementation.
Assume having a map of all Mongo.Collection
instances:
const collectionsMap = {};
Since you may not want to store the FilesCollection instance (because it is not a Mongo.Collection
), you can still reference the underlying Mongo.Collection:
const Images = new FilesCollection({collectionName: 'Images'});
collectionsMap.Images = Images.collection;
Access the FilesCollection by reference:
const Images = collectionsMap.Images.filesCollection;
Meteor-Files | Support | Try ostr.io |
---|---|---|
If you found this package useful, — star it at GitHub and support our open source contributions with a monthly pledge, or submit a one-time donation via PayPal | Monitoring, Analytics, WebSec, Web-CRON and Pre-rendering for a website |