[Meteor 1.3] Best practices for calling Mongo Update from callback

Hi guys.

I’m trying to use this lib.

The library creates a pyramid of doom of callbacks:

my_sheet.useServiceAccountAuth(creds, function(err){
    // getInfo returns info about the sheet and an array or "worksheet" objects
    my_sheet.getInfo( function( err, sheet_info ){
        console.log( sheet_info.title + ' is loaded' );
        // Meteor update collection here

To make it work I had to use Meteor.bindEnvironment() twice, a function which is not on the docs so I guess it’s not considered a best practice.

I get that the ultimate solution to avoid a pyramid of doom is to use promises or async await, but when we meet nested callback code what is the beast approach to update collections or reactive vars?

Using bindEnvironment is okay - it’s not in the docs, but it is mentioned as an acceptable option in the Handling NPM callbacks section of the Guide. The docs are known to be incomplete in a few areas (Meteor.defer anyone?). Definitely consider opening an issue or better yet submit a docs PR.

1 Like