I am starting to work with Meteor and I am running in to my first issue. I am trying to insert a item in to my collection. I get the below console log error. Can someone help a Meteor noob?
insert failed: Method not found
This is the line that cause the error:
Videos.insert({name: el.value});
My js file:
var Videos = new Meteor.Collection("videos");
if (Meteor.isClient) {
Template.videoList.video = function() {
return Videos.find();
}
Template.videoForm.events({
'click button': function(e, t){
var el = t.find("#name");
Videos.insert({name: el.value});
el.value = "";
}
});
}
When you try Video.insert. Meteor is trying to insert both on the client and on the server as well. Meteor design it this way to help reflect the change instantly on the client(Latency Compensation).
When your Video collection is not defined on the server (not in Meteor.isServer wrap or file that can accessed by Server). It will throw the error you encountered.
If you want to insert to client only. You can access to it by _collection. So your insert statement would be Videos._collection.insert(values);
You can find more info here in this screen cast: http://www.eventedmind.com/feed/meteor-anatomy-of-a-collection-insert
To create a local-only collection:
MyLocalCollection = new Collection(null);
(reference doc here)
About "_collection":
_collection
is an undocumented property that behaves strangely in many cases. You might prefer not to use it.
About manipulating only the local cache of a client-server collection:
There is no way to do this directly. However, it is very easy to create a dynamic local mirror of an existing collection (in my experience, this is the way to go for any complex UI). See this post.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With