[SOLVED] Getting related document using Meteor Methods

Hello there !

I’m trying to setup a simple method to find a related document.

Actually here’s my function :

get_reldoc: function(col, remote_col, remote_field) {
        return remote_col.findOne({_id: col.findOne({_id: id}).remote_field});

In my helper, the old way i’m using to get a customer is this way :

customer: () => {
        var id = FlowRouter.getParam('_id');
        return Partners.findOne({_id: Pipelines.findOne({_id: id}).partners_id});

And i want to be able to do this :

customer: () => {
        var id = FlowRouter.getParam('_id');
        return Meteor.call('get_reldoc', Pipelines, Partners, partners_id);

But when i call the methods, it’s simply not working. Does anyone knows why ?

Thanks Meteor Community ! :slight_smile:

Happy coding,


You can’t pass an object like that.

When you use Meteor.call, you’re serializing the arguments as json and posting them to the server. Your Pipelines is being treated as a plain key-value object with no functions.

If you want to dynamically find collections, you’ll need to create a dictionary of your collections, pass a string to the method, and look it up in the method implementation.

1 Like

Okay ! I’ll do it this way. Thanks :slight_smile:

Method.call is asynchronous on the client and needs to be provided with a callback function.

Meteor.call('get_reldoc', Pipelines, Partners, partners_id, function(error, result){
  if(error) {
  } else {
    // handle result

I was about to post a new question about it, for handling errors on mail send. You answered it here ! :slight_smile: Thanks @jamgold !