Skip to content

Commit 328cd91

Browse files
committed
v.2.0.2 includes referencing from mongo collection instances
1 parent 4eb3210 commit 328cd91

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ var Images = new FilesCollection({
3434
}
3535
})
3636

37+
// if you want to make use of dburles:mongo-collection-instances
38+
// you need to create a 'parent' reference to the underlying collection
39+
Images.collection.filesCollection = Images;
40+
3741
if (Meteor.isClient) {
3842
Meteor.subscribe('files.images.all');
3943
}
@@ -44,7 +48,8 @@ if (Meteor.isServer) {
4448
});
4549
}
4650
```
47-
__Note:__ `Images` variable must be attached to *Global* scope. And has same name (*case-sensitive*) as `collectionName` option passed into `FilesCollectio#insert({collectionName: 'Images'})` method, `Images` in our case.
51+
__Note:__ If you don't use Mongo Collection instances, then the `Images` variable must be attached to *Global* scope. And has same name (*case-sensitive*) as `collectionName` option passed into `FilesCollection#insert({collectionName: 'Images'})` method, `Images` in our case.
52+
4853

4954
- Define your schema and set the `autoform` property like in the example below
5055
```javascript

lib/client/fileUpload.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Template.afFileUpload.onCreated(function () {
1313
}
1414
console.log(this.data);
1515
this.collection = Mongo.Collection.get
16-
? Mongo.Collection.get(this.data.atts.collection)
16+
? Mongo.Collection.get(this.data.atts.collection).filesCollection
1717
: Meteor.connection._mongo_livedata_collections[this.data.atts.collection];
1818
this.uploadTemplate = this.data.atts.uploadTemplate || null;
1919
this.previewTemplate = this.data.atts.previewTemplate || null;
@@ -49,7 +49,7 @@ Template.afFileUpload.helpers({
4949
uploadedFile() {
5050
var collectionName = Template.instance().collectionName();
5151
var collection = Mongo.Collection.get
52-
? Mongo.Collection.get(collectionName)
52+
? Mongo.Collection.get(collectionName).filesCollection
5353
: global[collectionName];
5454
return collection.findOne({
5555
_id: Template.instance().fileId.get() || this.value
@@ -75,11 +75,13 @@ Template.afFileUpload.events({
7575
},
7676
'change [data-files-collection-upload]'(e, template) {
7777
if (e.currentTarget.files && e.currentTarget.files[0]) {
78+
7879
var collectionName = template.collectionName();
7980
var collection = Mongo.Collection.get
8081
? Mongo.Collection.get(collectionName)
8182
: global[template.collectionName()];
82-
var upload = collection.insert({
83+
84+
var upload = collection.filesCollection.insert({
8385
file: e.currentTarget.files[0],
8486
streams: 'dynamic',
8587
chunkSize: 'dynamic'

0 commit comments

Comments
 (0)