Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

observer method doesn't trigger #57

Open
huvber opened this issue May 28, 2015 · 3 comments
Open

observer method doesn't trigger #57

huvber opened this issue May 28, 2015 · 3 comments

Comments

@huvber
Copy link

huvber commented May 28, 2015

I'm trying to understand why the method added removed and changed never trigger on my system. I create a little server in meteor that publish a collection like this

Meteor.publish('coll',function(){
  return Coll.find();
});

and in my nodejs software I write this code:

  var ddp = new DDPClient({
    host: this.config.server.host,
    port: this.config.server.port,
    autoReconnect: true,
    autoReconnectTimer: 500,
    maintainCollections: true,
    useSockJs: true
  });

ddp.connect(function(err, wrec) {
  DDPLogin.loginWithEmail(ddp, config.server.user, config.server.passwd, function (err, userInfo) {
        ...
       ddp.subscribe('mp3s');
       var obs = ddp.observe('coll');
       obs.added = function(id) {
           console.log('evvai');
           entry = ddp.collections.coll.find(id);
          console.log(entry);
       };
  });
  ....
});
@vsivsi
Copy link
Member

vsivsi commented May 29, 2015

Hi, I believe you may have the collection name and publish name reversed in your code... Also find() needs some selector, right?

So something like:

Server:

var Coll = new Mongo.Collection('collName');
Meteor.publish('pubName', function () {
     return Coll.find({});  // Note {} as selector!
});

node.js client:

// Omit DDP connection details
ddp.subscribe('pubName');
var obs = ddp.observe('collName');
obs.added = function (id) {
/// ...
};

@pennsong
Copy link

I have the same problem too,
but the following code is working:

     var observer = ddpClient.collections.observe(()=>{
        return ddpClient.collections.todos.find();
      });

      observer.subscribe(()=>{
        console.log('sss');
      });

could you please explain why?

@pennsong
Copy link

Sorry, actually I was confused by the package "npm install ddp-client"
there is no problem with this "npm install ddp" package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants