Meteor-Community-Packages / meteor-collection-hooks

Meteor Collection Hooks
https://atmospherejs.com/matb33/collection-hooks
MIT License
657 stars 92 forks source link

TypeError: Cannot call method 'insert' of undefined #76

Closed dalgard closed 9 years ago

dalgard commented 9 years ago

It seems like the collection-hooks package somehow isn't properly applied. I've removed all other 3rd party packages from the project and the only active code is this:

Projects = new Mongo.Collection("projects");

Projects.before.insert(function () { ... });

What gives? I've recently upgraded Meteor and packages to newest versions. How to troubleshoot? Thanks.

fusepilot commented 9 years ago

Had the same problem. Not ideal but specifing the current version fixed it for me.

matb33:collection-hooks@0.7.6
matb33 commented 9 years ago

Possibly due to using api.versionsFrom of 0.9. Not sure but that's where I'll start. Will I be able to repro this easily? Just in case, are you willing to prepare me a quick project that exhibits the issue?

eportico commented 9 years ago

I have the same problem with Meteor 1.0.1

dalgard commented 9 years ago

Thanks for posting back. Your comments sent me in the right direction – when I create a new project, version 0.7.6 is used automatically and the problem doesn't arise.

The reason why the wrong version is used, I'm pretty sure, is that I have added sewdn:collection-behaviours which has these lines in web.browser.json:

"uses": [
  {
    "package": "matb33:collection-hooks",
    "constraint": "0.7.3"
  }
]
dalgard commented 9 years ago

Meteor tells me all my packages are updated, but when I browse the code for sewdn:collection-behaviours on GitHub, I note that the package.js file of that project does refer to the correct version of matb33:collection-hooks, i.e. the most recent.

I wonder whether the issues all stem from packages not being up to date on Atmosphere?

dalgard commented 9 years ago

sewdn:collection-behaviors exists in version 0.2.0 on GitHub as opposed to 0.1.5 on Atmosphere, and 0.2.0 has the most recent version of matb33:collection-hooks as its constraint, so there's no problem.

I'm now using the sewdn:collection-behaviors package by cloning the git repo into my packages/ folder which is working okay (git clone https://github.com/Sewdn/meteor-collection-behaviours.git).

Atmosphere still has some way to go, in my opinion, such as closer integration with GitHub...

ibussieres commented 8 years ago

This might sound stupid, but for me, it was simply because I am using package file structure and hadn't added matb33:collection-hooks to package.js dependencies.

nicejwjin commented 5 years ago

I don't think this question is matched perfectly but argument of '.before.findOne (userId, selector, options) -> ' functions are all undefined, {} something like that even the findOne's result was fine. I can't catch anything for these stupid situations..

capi1O commented 5 years ago

Ran into this issue using meteor 1.8.

Tried to use version 0.9-rc4 (from the github repo) but got the same error. Any clue ?

After siwtching to branch meteor-1.6.1 I now have another error instead :

Error: First argument to new Mongo.Collection must be a string or null