-
-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #468 from VeliovGroup/dev
v1.8.2
- Loading branch information
Showing
6 changed files
with
74 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
## *FilesCollection* Instances and *Mongo.Collection* Instances | ||
|
||
While *FilesCollection* has a direct reference to a [`Mongo.Collection`](http://docs.meteor.com/#/full/mongo_collection), | ||
the `Mongo.Collection` has a back-reference to the *FilesCollection* itself. | ||
|
||
The reference chain is as the following: | ||
|
||
```javascript | ||
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); | ||
``` | ||
|
||
|
||
### Using dburles:mongo-collection-instances | ||
|
||
In Meteor for `Mongo.Collection` instances management, we suggest to use [dburles:mongo-collection-instances](https://github.com/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. | ||
|
||
```bash | ||
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. | ||
|
||
```javascript | ||
const Images = new FilesCollection({collectionName: 'Images'}); | ||
```` | ||
|
||
To retrieve *FilesCollection* use - `Mongo.Collection.get('collectionName')`: | ||
|
||
```javascript | ||
const ImagesCollection = Mongo.Collection.get('Images'); | ||
const Images = ImagesCollection.filesCollection; | ||
```` | ||
### Using a custom collection instance management | ||
This simplified example shows, how to make use of that technique in your own implementation. | ||
Assume having a map of all `Mongo.Collection` instances: | ||
```javascript | ||
constvar 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: | ||
|
||
```javascript | ||
var Images = new FilesCollection({collectionName: 'Images'}); | ||
collectionsMap['Images'] = Images.collection; | ||
```` | ||
Access the *FilesCollection* by reference: | ||
```javascript | ||
var Images = collectionsMap['Images'].filesCollection; | ||
```` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters