As a learning exercise, I am redoing the “Try Meteor” tutorial as a package. I have committed the latest problem to GitHub : pkgd-todos. In the third step of the tutorial “Collections” I instantiate the Tasks collection in both client and server. I also try to insert an initial task in the collection, but in the browser I see “insert failed: Method not found”.
The actual code is in packages/todos-pkg/lib/collections/tasks.js
Tasks = new Mongo.Collection("tasks");
Meteor.startup(function () {
if (Tasks.find().count() === 0) {
Tasks.insert({ text: "Initial task", createdAt: new Date() });
}
});
I’ve tried a bunch of things, like adding api.use('autopublish');
but I don’t understand how the bug can happen at all. I mean, if I can instantiate a Mongo Collection and call its find() method, why can’t I even see its insert() method three lines below? If I wrap it in an isServer() condition, still nothing gets written to Mongo.
The code is all here : pkgd-todos.