[Solved] “Try Meteor” as a package. Snag #2. Client can't see Collection.insert() even if autopublish is used


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.


You have a typo in your package.js. It should be api.addFiles(['lib/collections/tasks.js'], ['client', 'server']);. Currently the file is only loaded on the client.


Oh crap! Sorry to waste your time.


Was just one minute :wink:


Yeah. But I get to feel stoopid for the rest of the day. :wink: