Subscribe from inside Meteor Methods / api?

Apologies for the odd title, I just didn’t know what to call this exactly. I have a structure like

    - api

andn from inside methodSet1 I need to do a find on the collection defined in methodSet2.

I have done

import { MethodSet2 } from './methodSet2.js'

inside methodSet1, but when I do

let someVar = MethodSet2.findOne({ criteria })

I get an error that someVar is undefined when I try to use the object a few lines later.

I feel like I need to subscribe to the publication of MethodSet2 data I have, but I don’t really know how to do that outside of a template.

Am I missing something here?

Still interested in how one might do this, but I went back and basically did the lookup of info from the template then passed the info with the Method Call.

If a findOne lookup has criteria that don’t result in a match, you’ll also get back undefined – I’m guessing you already tested with something like MethodSet2.findOne({}) to confirm?

On the server you don’t need to subscribe, because the server has full access to all collections. I recommend you check out methods in the meteor guide

@vigorwebsolutions it’s odd, I was able to get results in the Meteor Mongo console using the query and criteria, and I made sure the criteria was set prior to the query using it, but no, didn’t try it in the code with no criteria. I’ll give it a go.

1 Like