简体   繁体   中英

Add Collection to meteor.js project

I'm trying to add a Collection to my Meteor.js. I used a template from meteorkitchen and added some code:

In my home.js file (subfolder in client folder) I have this code:

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

Template.HomeSection2Content2.helpers({
    tasks: function() {
        return Tasks.find();    
    }
});

I know that my home.html file works, because if if replace the code in the TemplateHelper with:

Template.HomeSection2Content2.helpers({
tasks: [
{ text: 'This is task 1' },
{ text: 'This is task 2' },
{ text: 'This is task 3' },
  ],
});

everything works correctly.

I also added

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

to my server.js file.

When i try to add something through my MongoDB Shell to this collection, nothing happens to the FrontEnd. I don't get an error message

Data is still being published behind the scenes through the autopublish package. That means that your entire database is being published on the server, and subscribed to on the client. Once you remove that package, you must manually set up all pub/sub calls

Problem solved!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM