Meteor Method Halting on Insert

This is the code for my Meteor method:

fetchGumroadData: () => {
    gumroadFunc(function(result){

      console.log(result.length);

      result.map(function(ele, index){
        console.log(index);
        Sales.insert({
          text: 'testing',
          createdAt: new Date(),
        });
      });

    });
  }

console.log(result.length) outputs 28 in the server logs, so we know that result is okay.

But after console.log(index) prints out 0, the process halts. This means that the insertion into the Sales collection isn’t working out and the code halts there.

If you remove the Sales insertion command, the server logs indicate that it iterates through each element of the array just fine. console.log(index) prints from 0 to 27 just as expected. I also tested it with console.log(ele) and it displays all 28 sets of data just fine (they’re just javascript objects). However, when I try to insert, it seems to halt.

the insertion that you did will be a synchronous call, you can try to add a callback on the insert call, also check this

Thanks for the reply. It seems that my problem is due to gumroadFunc() having async code inside. I have made a StackOverflow question expanding on the issue. I’ll refrain from posting another thread here until I get no response from StackOverflow.