meteor-collection-hooks
meteor-collection-hooks copied to clipboard
before.insert won't run before collection2 schema check on server side when calling via method
Hi, @matb33
Here's a repo to reproduce the error
When inserting inside meteor method, only client side runs the before.insert hook before collection2 's schema check. Server side won't run the hook, and fails the schema check. Error message:
Exception while invoking method 'insertTest' Error: Created at is required
I20151123-01:04:26.343(8)? at getErrorObject (packages/aldeed_collection2/packages/aldeed_collection2.js:425:1)
I20151123-01:04:26.343(8)? at [object Object].doValidate (packages/aldeed_collection2/packages/aldeed_collection2.js:408:1)
I20151123-01:04:26.343(8)? at [object Object].Mongo.Collection.(anonymous function) [as insert] (packages/aldeed_collection2/packages/aldeed_collection2.js:177:1)
I20151123-01:04:26.343(8)? at [object Object].Meteor.methods.insertTest (collection-hook-serverside-test.js:33:12)
I20151123-01:04:26.343(8)? at maybeAuditArgumentChecks (livedata_server.js:1698:12)
I20151123-01:04:26.343(8)? at livedata_server.js:708:19
I20151123-01:04:26.343(8)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20151123-01:04:26.344(8)? at livedata_server.js:706:40
I20151123-01:04:26.344(8)? at [object Object]._.extend.withValue (packages/meteor/dynamics_nodejs.js:56:1)
I20151123-01:04:26.344(8)? at livedata_server.js:704:46
I20151123-01:04:26.344(8)? Sanitized and reported to the client as: Created at is required [400]
Am I doing something wrong? Or is this a bug?
Thanks! YuHuaiChen
Looks like a load order issue. See https://github.com/matb33/meteor-collection-hooks/issues/153
Unfortunately, changing the order of the dependencies inside my package doesn't fix this. Anyone have another workaround? Not being able to use collection-hooks and collection2 together in Meteor methods would lead to a pretty significant setback in the app I'm working on.
@ryanfields did you figure this out?
@huevoncito it's definitely not a load order
@yogiben Nope. I've stopped using collection-hooks. I didn't really find any good alternatives though. I just do what I can to work around the need for hooks now.
Looks like schemas/hooks order is inverted between client and server side: #154.