Meteor: insert failed: Method not found
Make sure you've also declared your collection on the server as well as the client.
In your code above @VINs = new Meteor.Collection("vins")
in both the client and server so what it might be is that you've put your code into the /client
directory?
If so this means that the code will only be run on the client, even though you have the else
for the if Meteor.isClient
block.
To rectify this, copy the line you used into a .coffee
file in the /server
directory:
@VINs = new Meteor.Collection("vins")
Related videos on Youtube
Steve Ross
Updated on September 15, 2022Comments
-
Steve Ross over 1 year
I am receiving the
insert failed: Method not found
log message and it probably is the result of what is described in these threads:- Meteor using a local connection results in error: insert failed: 404 -- Method not found
- Getting a error inserting in to a Meteor Collection
However, I'm not seeing how. Let me show the code in hopes that will explain more clearly. I'm using Coffeescript:
if Meteor.isClient @VINs = new Meteor.Collection("vins") scoped_vins = @VINs Template.vins.events = "click .icon-plus-sign": -> console.log "this is #{this}" realVIN = $("#your-vin").val().replace /\D/g, '' console.log "user id is: #{Meteor.userId()} vin is #{parseInt(realVIN)}" VINs.insert number: parseInt(realVIN), owner: Meteor.userId() if Meteor.userId() $("#your-vin").val('') else @VINs = new Meteor.Collection("vins")
I'm totally a n00b with Meteor, but what I've gleaned from the above-cited threads is that the collection must be available on the client and the server. Is that not what I have done, or am I developing Coffee-blindness?
Thanks!
-
Dan Dascalescu almost 9 years
-
Dan Dascalescu almost 9 yearsA good first step as a n00b is to remove any code that's not relevant to reproducing the error. E.g. the
replace
on the VIN probably has nothing to do with the error, so trying removing it. Does the error still occur? Keep removing code until you isolate the minimum reproduction case.
-
Steve Ross over 10 yearsAnd... you nailed it on the first try :) It was a combination of my lack of understanding and some directory reorganization.
-
Tarang over 10 yearsI wasnt too sure! If it solved your problem you also don't need the
if Meteor.isClient..else..
because it will already run on the client and server depending on the directories the files are in. If you put your files in the root directory then you could use theif Meteor.isClient
(like the todos example) -
Steve Ross over 10 yearsRight. Well, thanks! I'm getting there. Just not as quickly as I'd guessed. Only my second mongo project and I have to keep my head out of the relational space.
-
Tarang over 10 yearsCool stuff, if you get stuck on anything else ask away. Will be sure to at least try and answer