Meteor Method - Find in collection inside callback

I’m having troubles when fetching results from a collection find. When I try to fetch the find results I get the following error:

Error: Can’t wait without a fiber

Any suggestions?

import { Meteor } from 'meteor/meteor';
import FB from 'fb';
import Customers from './collections/customers';

FB.mapi = Meteor.wrapAsync(FB.napi);

Meteor.methods({
    'facebookImport': function(access_token) {

        //SYNC - Get facebook user info
        let res = FB.mapi('me', {
            fields: [
            'id', 
            'name',
            'email',
            ],
            access_token: access_token
        });

        //Get user's books
        FB.api('me/books', {
            fields:['data'],
            access_token: access_token
        }, function(res) {
        //    console.log(res);
            console.log(Customers);
            let a = Customers.find({id: res.id}).fetch();
            console.log(a);
        });
}
});

I’d probably try this first:

let a = Promise.await(Customers.rawCollection().find({ id: res.id })).fetch();
1 Like

hi!

i’m reciving error

TypeError: Promise.await is not a function app.js?..8ed267c (line 241, …

please suggest what I’m doing wrong

Meteor.methods({
    'tasks.get': async function(params) {
        const result = Promise.await(Task.find(params));
        return result;
Template.body.helpers({
'tasks': function() {
return Meteor.call('tasks.get', {});

Oops - you will need to add the promise package:

meteor add promise

and (if you’re using imports)

import { Promise } from 'meteor/promise';

Oh - also - you don’t need async methods with Promise.await (won’t do any harm, though).