What does it mean when a Collection insert results in a 404?

Tags: meteor
By : Benson
Source: Stackoverflow.com

I have a very simple test app in meteor, and I've created a collection like so:

var people = new Meteor.Collection("people");

When I try to do a simple insert, like this:

people.insert({name: "Benson"});

I get a 404 error with the text "Method not found". I admit there's a good chance I've fat-fingered something here, but I'd love to know both what's wrong, and why the error is so opaque (i.e. where it's coming from).

By : Benson

This error almost certainly means you've only defined people on the client, but not on the server. The new Meteor.Collection('people') declaration has to also run on the server, or else the server doesn't know how to run your insert command.

Be sure you're calling new Meteor.Collection on both the client and the server. Are you calling it inside if (Meteor.is_client), or in a file under the client subdirectory?

Some more details: On the server, new Meteor.Collection defines three remote methods (Meteor.methods) that insert, update, and remove documents in the named MongoDB collection. On the client, the same command creates an in-memory minimongo collection that lives inside the browser, and defines three stubs that simulate the methods by applying the same change to the minimongo collection. By only declaring the collection on the client, your client code runs the local insert just fine, but when it asks the server to perform the real insert, the server has no idea what method you've asked it to execute.

If you want to use Collection only on Client side and you don't need to save that data to server you can declare your collection in "client" folder or in .isClient() function by passing null to the constructor like this:

// Some other code

onlyClientCollection = new Meteor.Collection(null);

// Some other code
By : Drag0

This video can help you solving your question :)
By: admin