Call Stack exceeded when passing a Collection as an argument to Meteor.call

In my logs I have this:

W20200408-23:28:01.485(-5)? (STDERR) RangeError: Maximum call stack size exceeded
W20200408-23:28:01.485(-5)? (STDERR)     at Object.EJSON.clone (packages/ejson/ejson.js:551:15)
W20200408-23:28:01.486(-5)? (STDERR)     at packages/ejson/ejson.js:600:22
W20200408-23:28:01.486(-5)? (STDERR)     at Array.forEach (<anonymous>)
W20200408-23:28:01.486(-5)? (STDERR)     at Object.EJSON.clone (packages/ejson/ejson.js:599:13)
W20200408-23:28:01.486(-5)? (STDERR)     at packages/ejson/ejson.js:600:22
W20200408-23:28:01.486(-5)? (STDERR)     at Array.forEach (<anonymous>)
W20200408-23:28:01.486(-5)? (STDERR)     at Object.EJSON.clone (packages/ejson/ejson.js:599:13)
W20200408-23:28:01.486(-5)? (STDERR)     at packages/ejson/ejson.js:600:22
W20200408-23:28:01.486(-5)? (STDERR)     at Array.forEach (<anonymous>)
W20200408-23:28:01.486(-5)? (STDERR)     at Object.EJSON.clone (packages/ejson/ejson.js:599:13)

this occurs in a deep callback structure .

Essentially, I have defined connecthandlers in WebApp, the handler receives a file from an upload, and I write it to a temp file. Then , I read the file, and write it into a Meteor-files collections, then I attempt to call a Meteor function with the file document, so that I can upload it to our video hosting service:

if(fileRef.isVideo) {
  Meteor.call('video.uploadToSprout', fileRef, Attachments, (error, result) => {
    if (error) {
      console.error(error);
    } else {
      console.log('upload returned.');
    }
  });
}

(‘Attachments’ is a Collection)

Then, I return the fileRef to the client (as requied by my dropzone component)

When I send the Attachment Collection, I get the error above. When I leave it out, it works fine.

I have been able to send Collections as Meteor.call arguments before, so I guess it is something particular to the particular chain of callbacks and bound environments I have here.

Any ideas?

More than likely this crashes due to EJSON trying to parse the collection object so that it can be sent over DDP to the server. I don’t know your specific reasoning behind trying to do this, but surely sending the name of the collection or some other work around would be preferable.

1 Like

What is the preferred way of getting a collection object by name? I see some methods out there by using some private API’s, but many of the posts are a bit old at this point and perhaps things have changed.

Honestly the easiest way is to just use the _name property on the collection unless you are going to create a factory or something similar to to create and store your collections by name.