JoethaCoder
JoethaCoder

Reputation: 506

Meteor DDP Publication/Subscription

I have managed to get 2 apps connect via DDP, but I am a little unsure on how to publish data from the origin server.

Here is what I am trying on the client:

Template.Dashboard.onCreated(function() {
  Meteor.remoteConnection = DDP.connect('http://localhost:3030');
  this.subscribe('templatePublication', {
    connection: Meteor.remoteConnection
  });
});

That is supposedly calling a publication on the origin server. It is not throwing any errors, but at the same time it is not producing any documents, which it should as the publication is a simple Collection.find({});

Just curious if there is something I am missing…

Upvotes: 2

Views: 278

Answers (1)

JoethaCoder
JoethaCoder

Reputation: 506

I solved this! It seems I overcomplicated it. It looks like you have to do it like this (this is all on client):

import { DDP } from 'meteor/ddp-client'

var remote = DDP.connect('http://localhost:3030/');
Templates = new Meteor.Collection('templates', remote);

Template.Dashboard.onCreated(function(){ 
  remote.subscribe('templatePublication');
});

Template.Dashboard.helpers({
  listTemplates: ()=>{
    return Templates.find();
  }
});

Upvotes: 3

Related Questions