Closed wI2L closed 10 years ago
It sounds like a loading order issue. Your hook definition may be getting read before your collections gets a chance to be defined
I was thinking of that indeed. I tried to rename my models/
to zodels/
, to see if its related to an alphabetical loading order in the root app folder, but it didnt resolved the problem.
My publications functions are also in the server/
directory, and i never got this error in the past because of that.
I also tried to put the required file in a sub lib/
folder inside server/
.
Ok. I found the solution with this post.. https://groups.google.com/forum/#!topic/meteor-talk/3TgKLYHrbNg
I just put my hooks definitions inside a sudirectory called server
in my models/
directory.
Hook definition is not sent to the client, so the behaviour is ok.
Hello..
I am currently trying to use an "afterInsert" hook on one of my collections.
This collection is defined in the folder
models/collections/
.The folder
models/
also contains another folder namedschemas
, used to store "Simple-Schema" schemas. This is not revelant here, but i just want to precise, because its usual to place collections files incollections/
Because i want my collection hook to be exectuted on the server, i wrote it into a file which is stored in
server/collections/hooks/
. I could've addMeteor.isServer()
after the definition of my collection, but even if this code would be only executed by the server, i understood that it would be sent to the client.Doing everything like that, i got an erreor at meteor startup (full stacktrace) :
ReferenceError: VServers is not defined
whereVServers
if of course my collection name.I ensure you i dont use the keyword
var
to define my collection.Any idea of how i can do things ?
Meteor Collection Hooks mainpage says, "Works across both client, server or a mix", but i would like it to work only on the server, i do not trust the user for the operation that will be performed by the hook.
Regards,
William