Tim Zhukov-Khovanskiy
Tim Zhukov-Khovanskiy

Reputation: 500

Meteor Collection is not being created on back- end

I'm working through a tutorial on Meteor, and to my understanding this should create a collection in Meteor's Mongo instance:

// simple-todos.js
Tasks = new Mongo.Collection("tasks");

if (Meteor.isClient) {
  // This code only runs on the client
  Template.body.helpers({
    tasks: function () {
        console.log(Tasks.find({}));
        return Tasks.find({}, {sort: {createdAt: -1}});
    }
  });
}

I've looked at similar posts, but they had created the collection inside client code block, so I moved it up as a global variable.

When I look in back end for mongo, I see only collection "system.indexes" registered. I'm not sure what I'm doing wrong, it seems like it should be pretty simple. Thanks in advance.

Upvotes: 0

Views: 706

Answers (1)

SylvainB
SylvainB

Reputation: 4820

Even if you declared a new collection in your app, Meteor will not actually "create" a collection in mongodb until you actively insert something in it. Still your app will behave like it has an empty collection in store.

So in order to "see" the collection in mongo, you will need to insert data in your collection, through your mongo client or your meteor app. Or you can create the collection manually using mongo. (but to what extent...)

Upvotes: 2

Related Questions