Why am I unable to create collections during runtime? (=> "Called retrieveOriginals without saveOriginals" error)

Hello everybody!

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.

What am I doing wrong?

Thanks a lot for any hints in advance!

Simon

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.

I am not sure what the current error point to.

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:

Simon

Any help welcome!

good luck https://github.com/meteor/meteor/issues/3025

Finally, I got it. Adding Meteor.defer actually did the trick. Not absolutely sure why though…

The follwing code works:

if (Meteor.isClient) {
Template.hello.events({
    'click button.new': function () {
        Meteor.call('newCollection');
    }
})

}

if (Meteor.isServer) {

Meteor.methods({
    'newCollection': function () {
        Meteor.defer(function() {
            newCol = new Mongo.Collection("newColl");
            newCol.insert({name: "Hallo"});
        })

    }
})

}