(SOLVED) New Mongo.Collection is undefined on startup

Hi I’m in the middle of trying the tutorial as typescript, but got stuck early on. When I run meteor run I get the error

/home/xxx/.meteor/packages/meteor-tool/.2.4.0_1.1ysxd7i.qhi2++os.linux.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:280
						throw(ex);
						^
TypeError: Cannot read property 'find' of undefined
W20210925-17:18:20.496(-7)? (STDERR)     at server/main.ts:9:23

Why?

server/main.ts

import { Meteor } from 'meteor/meteor';
import { TasksCollection } from '/imports/api/TaskCollection';

const insertTask = (taskText: any) => TasksCollection.insert({ text: taskText } as any);

Meteor.startup(() => {
  if (TasksCollection.find().count() === 0) {  // <--- Error thrown here as 'TasksCollection' is undefined
    [
      'First Task',
      'Second Task',
      'Third Task',
      'Fourth Task',
      'Fifth Task',
      'Sixth Task',
      'Seventh Task'
    ].forEach(insertTask)
  }
});

imports/api/TasksCollection.ts

import { Mongo } from 'meteor/mongo';
 
export const TasksCollection = new Mongo.Collection('tasks');

The problem was with my VS CODE not auto saving the file… After saving the changes to the above settings, it works…

1 Like

Glad you solved it :wink: