I've encountered an issue in my Meteor app where a Meteor method takes a collection as a parameter and attempts to run the mongo insert
command on that collection to create a new document. The code is set to run every 10 seconds using setInterval
.
The collection is defined as:
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, when running the code, the console displays the following error:
I20141030-14:58:06.716(-4)? Exception in setInterval callback: TypeError: Object #<Object> has no method 'insert'
Why is this happening? Can a collection be passed in as a parameter in this context? Any insights would be appreciated. Thank you!