Skip to content

Commit 488cc2c

Browse files
committed
use two fallbacks to get collection
1 parent 2d806ed commit 488cc2c

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lib/client/fileUpload.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,26 @@ Template.afFileUpload.onCreated(function () {
2222
};
2323
}
2424

25+
// primary method: use dburles:mongo-collection-instances
2526
if (Mongo.Collection.get) {
2627
const mongoCollection = Mongo.Collection.get(this.data.atts.collection);
2728
this.collection = mongoCollection && mongoCollection.filesCollection;
28-
} else {
29-
// if newer than 2016 use _stores
30-
// else use _mongo_livedata_collections
31-
// see https://github.com/meteor/meteor/pull/5845
29+
}
30+
31+
// 1. fallback using global scope
32+
if (!this.collection) {
33+
this.collection = global[this.data.atts.collection];
34+
}
35+
36+
// 2. fallback using Meteor.connection / local collections
37+
// if the Meteor release is newer than 2016 -> use _stores
38+
// else use older _mongo_livedata_collections
39+
// see https://github.com/meteor/meteor/pull/5845
40+
if (!this.collection) {
3241
const storedCollection = Meteor.connection._stores[this.data.atts.collection];
33-
const liveDataCollection = storedCollection && storedCollection._getCollection
42+
this.collection = (storedCollection && storedCollection._getCollection)
3443
? storedCollection._getCollection().filesCollection
3544
: Meteor.connection._mongo_livedata_collections[this.data.atts.collection];
36-
const globalCollection = global[this.data.atts.collection];
37-
this.collection = liveDataCollection || globalCollection;
3845
}
3946

4047
if (!this.collection) {

0 commit comments

Comments
 (0)