Being new to Meteor and trying to walk the first steps around I ran into a problem that seems weird to me; I want the user to be able to create a arbitrary collection after starting Meteor. Doing so by
if (Meteor.isClient) { Template.hello.events({ 'click button': function () { var newCol = new Mongo.Collection(name); } }) }
doesn’t work because I miss the server part of new Mongo.Collection.
So I tried:
if (Meteor.isClient) { Template.hello.events({ 'click button': function () { var col = Meteor.call("newCollection", "testCollection"); col.insert({message: "Hello"}) } }) } Meteor.methods({ 'newCollection': function (name) { var newCol = new Mongo.Collection(name); return newCol; } })
However, this doesn’t work either. I get an “Called retrieveOriginals without saveOriginals” error.
well, this one var col = Meteor.call("newCollection", "testCollection");
is sync style and client side methods are executed as async
so you need to at least manage results from the method call in callback function.
Thanks for your hint, but sorry - I still don’t get it right. Even if I simplify the code like this:
if (Meteor.isClient) {
Template.hello.events({
'click button.new': function () {
Meteor.call('newCollection');
}
})
}
Meteor.methods({
'newCollection': function () {
newCol = new Mongo.Collection("newColl");
}
})
I still get the above error, though I am omitting any further database manipulation (like insert). Adding a callback function doesn't change anything either. Am I really the first person who tries to create a collection by a client side trigger during runtime? Is this such a silly idea? :frowning: