(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

TypeError: Cannot read property 'find' of undefined
W20210925-17:18:20.496(-7)? (STDERR)     at server/main.ts:9:23



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'


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: