In my Meteor app, I have a Meteor method that takes the collection as a parameter and tries to run the mongo insert
command on that collection to create a new document. The code runs every 10 seconds using setInterval
.
Collection is defined:
My_Collection_Name = new Meteor.Collection('my_collection_name');
Server code:
var collection = My_Collection_Name;
var data = [1,2,3,'a','b','c'];
Meteor.call('createDocument', collection, data);
Method:
Meteor.methods({
createDocument: function(collection, data) {
collection.insert({
data: data
});
}
});
However, this returns the following error in the console:
I20141030-14:58:06.716(-4)? Exception in setInterval callback: TypeError: Object #<Object> has no method 'insert'
Why doesn't this work? Is it possible to pass in the collection as a parameter? Thank you in advance!