[Solved] Getting same results for all Meteor.call results in loop

I tried this code but getting the same result,

const resultPromises = i.map(async (element, index) => {
          return await new Promise(async (resolve) => await Meteor.call("fetchData", limit, index * limit, false, (error, result) => resolve(result)));
        })

Here is my “fetchData” method code:

'fetchData': function fetchData(limit, skip, checkCount){
      check([limit, skip], [Number]);
      check(checkCount,Boolean);
      const user = Meteor.user();
      if (!user) throw new Meteor.Error('not-authorized');
      let clientId = user.profile.clientId;
      let locations = Locations.find(
        { clientId },
        {
          sort: {
            locationName: 1,
          },
          fields: { updatedAt: 0, owner: 0 },
        }
      );
      if(checkCount) return locations.count();
      return locations.fetch();
  }

Your fetchData function don’t use the limit and skip variables. You must add then in the options of find.

3 Likes

ohhh @peernohell Thanks you… apologies it was my mistake. I have 7 slimier methods and i added skip and limit to all other methods, but missed in this, Thank you very much.
@smilingis @rjdavid @minhna apologies …