Insert on client side collection

609 views
Skip to first unread message

ServerMeta

unread,
Jan 19, 2015, 1:18:18 PM1/19/15
to meteo...@googlegroups.com
On meteor docs it says that Collection.insert is defined everywhere, but when I try it on the client it says method undefined.

I read that update and insert is denied by default on client side.

I have a collection which is useful only to the client. I dont care if they hack it, it will just mess the UI. I dont want to store it on the server, as it would only clog up resources.

How can I do insert on a client side collection?

Steve

unread,
Jan 20, 2015, 6:12:58 AM1/20/15
to meteo...@googlegroups.com
This should work. Can you please past some of your code?

ServerMeta

unread,
Jan 20, 2015, 6:39:43 AM1/20/15
to meteo...@googlegroups.com
I've now remembered that this is used as an example in discover meteor. Very strange.

So in my project I have insecure and autopublish.

/client/collections/videos.coffee

@videos = new Meteor.Collection("videos")


I open the website, I open the chrome javascript console, then:

Videos
Mongo.Collection {_makeNewID: function, _transform: null, _connection: Connection, _collection: LocalCollection, _name: "videos"…}

Videos.find().count()
0

Videos.insert({title: "A second post"});
"3bGCyTFrKXF4ESStK"
debug.js:41 insert failed: Method not found

ServerMeta

unread,
Jan 20, 2015, 6:44:53 AM1/20/15
to meteo...@googlegroups.com
Ok I found out you cant insert collection client side, but you have to use a specific command


Videos._collection.insert({title: "A second post"});
"4urKE3tikLJapKt3d"
Videos.find().count()
1


This is in contrast to what Discover Meteor says. When they changed that? Why I cant find any reference about it on the internet?

What else they changed? 

Steve

unread,
Jan 20, 2015, 7:55:50 AM1/20/15
to meteo...@googlegroups.com
This is not the correct way to use a client side collection. Collection._collection is an undocumented property that behaves strangely in many cases. You may prefer not to use it.

To create a local collection, use:
var myLocalCollection = new Collection(null);
(see doc here)

To manipulate locally a client-server collection, see this thread.

ServerMeta

unread,
Jan 20, 2015, 8:03:11 AM1/20/15
to meteo...@googlegroups.com
Ok so the trick to declare a client only collection, is not only to declare it in client code, but also to not give any name as option.

Thank you very much. Right now I feel like I have to write Meteor for Dummies (like me). :P
Reply all
Reply to author
Forward
0 new messages