-2

I would like to know if my implementation of publish and subscribe are correct. Im new at meteor js please help me. If you need more information regarding to my code, i am willing to give you the other source code. I read the documentation about publish and subscribe but I didn't understand the documentation about it.

import { Mongo } from 'meteor/mongo';
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';

export const Notes = new Mongo.Collection('notes');

if(Meteor.isServer) {
  Meteor.publish('secureData', function() {
    return Notes.find({});
  });
}

if(Meteor.isClient) {
  Meteor.subscribe('secureData');
}
Dom Ramirez
  • 2,132
  • 2
  • 23
  • 29
migmig
  • 15
  • 4

1 Answers1

0

The string you pass to new Mongo.Collection(<string>) should be the same as that which you passed to publish and subscribe. Try the same thing where "notes" replaces "secureData".

if(Meteor.isServer) {
  Meteor.publish('notes', function() {
    return Notes.find({});
  });
}

if(Meteor.isClient) {
  Meteor.subscribe('notes');
}

If you have further issues, please post examples showing how you're accessing this collection in your code.

Dom Ramirez
  • 2,132
  • 2
  • 23
  • 29
  • thank u for your response sir i will try the to change it immediately – migmig Oct 13 '17 at 08:31
  • Awesome! I’m glad it did. – Dom Ramirez Oct 13 '17 at 14:05
  • This answer is incorrect. You can call your publication whatever you want. It should have nothing to do with the name of the MongoDB collection. The question does not really state exactly what's wrong, but given the original code posted, it is simply a matter of data not being available on the client when the `console.log` is called. – MasterAM Oct 13 '17 at 18:08
  • Accountability is good, but I tested this by replicating @migmig's code in my own, working project's subscriptions. The project stopped working. It appears that the collection was available when I queried it in the console, but the data set was not reactive and my templates never updated. This test (which I've just repeated), in addition to the fact that migmig affirmed that this helped, leads me to believe I can stand my ground here. – Dom Ramirez Oct 13 '17 at 19:37
  • I'll remove my second paragraph about having one collection's subscription pull from another collections' data set as it was slightly off topic and was unclearly worded. You're welcome to edit further if you can point to something that nullifies my argument. – Dom Ramirez Oct 13 '17 at 19:37