vsivsi / meteor-file-collection

Extends Meteor Collections to handle file data using MongoDB gridFS.
http://atmospherejs.com/vsivsi/file-collection
Other
159 stars 37 forks source link

The global definition of Mongo.Collection has changed since the file-collection package was loaded. #128

Open g41n opened 8 years ago

g41n commented 8 years ago

Hi to all, this is the error I have replacing CFS with FC in an existing application:

gridFS_client.coffee:16
Uncaught Error: [The global definition of Mongo.Collection has changed since the file-collection package was loaded. Please ensure that any packages that redefine Mongo.Collection are loaded before file-collection.]

I don't know how meteor imports packages, if the order is in .meteor/packages FC is the last one.

I've also found that build packages are in .meteor/local/build/programs/web.browser/packages/ and, in alphabetical order, only webapp is after FC:

[...]
underscore.js
underscore.js.map
vsivsi_file-collection.js
vsivsi_file-collection.js.map
webapp.js
webapp.js.map

Other things I can check to verify the inclusion order?

Meteor version is 1.3.3.1

Any hint would be appreciated. Thanks in advance :)

vsivsi commented 8 years ago

Hi, yes, Meteor no longer provides any guarantees regarding package load order for packages that don't explicitly depend on one another. file-collection doesn't depend on any package that replaces the default Mongo.Collection object provided by Meteor. And it really can't because there are many such packages, with new ones probably being created all the time (or rather, new packages that depend on such packages). The only way file-collection could be made completely safe would be for it to depend on all other packages which is clearly untenable.

The solution? Don't use packages that Monkey patch or replace the objects that define the Meteor API. The check you've run into was added to this package to protect everyone's sanity. If Mongo.Collection is being modified by other packages in unpredictable ways, then I can't provide or reasonably support any standard of compatibility or data integrity for file-collection.

There's a long history for this issue, and it all stems from other packages (that provide useful functionality) being implemented using a terrible anti-pattern. It sucks, but it's not a problem I can fix. Here's a trail of tears for you to follow if you want to fully appreciate how messed up this is for Meteor:

https://github.com/meteor/meteor/issues/6416 https://github.com/vsivsi/meteor-defender https://github.com/vsivsi/meteor-file-sample-app/issues/2#issuecomment-120780592 https://github.com/vsivsi/meteor-file-collection/issues/61 https://github.com/vsivsi/meteor-file-collection/issues/125 https://github.com/vsivsi/meteor-job-collection/issues/97

dpatte commented 7 years ago

I had this issue, but moving vsivsi:file-collection to the end of the package list resolved it, at least for me.

egemon commented 6 years ago

Thank u @dpatte !