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

this._isRemoteCollection is not a function #125

Open ndarilek opened 8 years ago

ndarilek commented 8 years ago

Getting the following when attempting to insert a file. I don't think it's a file-collection issue as such, but more likely a bad interaction with aldeed:collection2. This package is recommended by the Meteor guide, but unless I'm missing something, it seems to monkeypatch Mongo.Collection (I.e. it doesn't create a Mongo.Collection2 which is ugly.) I seem to recall this being a bad thing for job-collection in the past, which makes me wonder if collection2 is doing the same thing. Unfortunately I don't recall what the fix was for job-collection since, IIRC, that was a year ago.

Does this look like the same bad package interaction? If so, is there any way I can restore the old Mongo.Collection, or whatever I need to do to get my Files.insert working?

Here is my console log. You're seeing an unhandled rejection because the code in question is packed in a promise:

Unhandled rejection TypeError: this._isRemoteCollection is not a function
    insert@http://localhost:3000/packages/mongo.js?hash=c6f177af2d62674ec14e1fb7978fce8fc2c62d4c:629:9
    Mongo.Collection.prototype[methodName]@http://localhost:3000/packages/aldeed_collection2-core.js?hash=78aa4a4dfcd4f54f1b080164dd6ca648f9f16f75:229:12
    FileCollection.prototype.insert@http://localhost:3000/packages/vsivsi_file-collection.js?hash=a6ab625089591595e70488517d22ef0217cb436d:1329:14
    _callee$@http://localhost:3000/app/app.js?hash=dfa5ac3bbb1d0f9d485c7e100f4f5010376cb4aa:232:48
    tryCatch@http://localhost:3000/packages/babel-runtime.js?hash=543034092ecef720d1732d8f72ab489f1877696f:619:37
    invoke@http://localhost:3000/packages/babel-runtime.js?hash=543034092ecef720d1732d8f72ab489f1877696f:893:22
    defineIteratorMethods/</prototype[method]@http://localhost:3000/packages/babel-runtime.js?hash=543034092ecef720d1732d8f72ab489f1877696f:652:16
    tryCatch@http://localhost:3000/packages/babel-runtime.js?hash=543034092ecef720d1732d8f72ab489f1877696f:619:37
    invoke@http://localhost:3000/packages/babel-runtime.js?hash=543034092ecef720d1732d8f72ab489f1877696f:695:20
    callInvokeWithMethodAndArg/<@http://localhost:3000/packages/babel-runtime.js?hash=543034092ecef720d1732d8f72ab489f1877696f:740:11
    callInvokeWithMethodAndArg@http://localhost:3000/packages/babel-runtime.js?hash=543034092ecef720d1732d8f72ab489f1877696f:739:16
    enqueue@http://localhost:3000/packages/babel-runtime.js?hash=543034092ecef720d1732d8f72ab489f1877696f:762:13
    defineIteratorMethods/</prototype[method]@http://localhost:3000/packages/babel-runtime.js?hash=543034092ecef720d1732d8f72ab489f1877696f:652:16
    require<.node_modules.meteor["babel-runtime"].node_modules["regenerator-runtime"]["runtime.js"]/</runtime.async@http://localhost:3000/packages/babel-runtime.js?hash=543034092ecef720d1732d8f72ab489f1877696f:782:9
    _callee@http://localhost:3000/app/app.js?hash=dfa5ac3bbb1d0f9d485c7e100f4f5010376cb4aa:224:12
    actionHandler@http://localhost:3000/packages/modules.js?hash=71943a27a09e6058feb30931670d90db574851a0:56624:19
    fileAdded@http://localhost:3000/app/app.js?hash=dfa5ac3bbb1d0f9d485c7e100f4f5010376cb4aa:191:25
    fileAdded@http://localhost:3000/app/app.js?hash=dfa5ac3bbb1d0f9d485c7e100f4f5010376cb4aa:102:7
    Resumable/$.fire@http://localhost:3000/packages/vsivsi_file-collection.js?hash=a6ab625089591595e70488517d22ef0217cb436d:165:32
    addFile/</<@http://localhost:3000/packages/vsivsi_file-collection.js?hash=a6ab625089591595e70488517d22ef0217cb436d:444:15

modules...74851a0 (line 52556)
log:
rv Object { type="FILE_ADDED",  payload=TypeError: this._isRemoteCollection is not a function,  error=true}
app.js?...76cb4aa (line 103)
ndarilek commented 8 years ago

Did a bit more research, and this workaround doesn't resolve the issue. I filed an issue requesting that collection2 be a separate, importable module, but not sure when that might happen.

vsivsi commented 8 years ago

I just tested for the presence of _isRemoteCollection() on a vanilla FileCollection object and it is present as expected. I'm not sure why adding Collection2 into the mix would change that (seems that would blatantly break all Collection2 collections), but as you say, this could be some weird interaction between Collection2 and file-collection.

I'm entirely fed-up with this monkey patching business, and simply don't provide support for use of my packages with libraries that monkey-patch Meteor. It is unsafe, insane and the mother of all anti-patterns. Trying to sort this stuff out is a giant waste of everyone's time. My guess is that you'll also find that Collection2 (like CollectionFS) is probably no longer supported.

Caveat emptor!