简体   繁体   中英

How to speed-up the mongoDB query response time in meteor?

I have a records of 15K in my collection with min 40 fields, I created a table which is generated from records. In this table i have various fileds as shown in image(from Excel sheet). 在此处输入图片说明

/client/main.js

Template.GetTable.helpers({
    'getTotalData':function(key1,key2){

        console.log("-------inside totalData()---------");
        const projects1 = Template.instance().distinct1.get();
        var filter1= _.map(projects1, col_8 => {
          return {col_8};
        });
        q={};
        p={};
        console.log(filter1);
        console.log(JSON.stringify(q));
            //var queryData=test.find(q).fetch();
            Meteor.call('getCountData',"all",function(err,count){
                if(err) 
                    console.log("Failed to call meteor..!");
                else{
                    console.log(count);
                    return count;
                }
            });
        },
  });

/server/main.js

Meteor.methods({
'getCountData':function(type){
              return test.find({"col_17" : " Query->:#####->x","col_8": { $regex: /^CQI?/i}}).count();  
    },
});

I was just testing for testing and i know how to get the count from DB. My problem is after all the rendering and the helpers are called the UI will load without any count data. But when i checked in debugger i got the right counts printed using "console.log()" and the UI is not updated. How can i resolve this issue? or is there any efficient way to solve this?

The UI problem is that you're doing a Meteor calling inside a helper and returning the result of the call to itself, not the helper.

Here's an example of what you're doing and what you SHOULD be doing.

SHOULD NOT:

Template.GetTable.helpers({
'getTotalData':function(key1,key2){
        Meteor.call('getCountData',"all",function(err,count){
            if(err) 
                console.log("Failed to call meteor..!");
            else {
                return count; // Being returned to this function, not helper fuction
            }
        });
    },

});

SHOULD:

var recVar = new ReactiveVar(false);
Template.GetTable.onCreated({
    Meteor.call('getCountData',"all",function(err,count){
        if(err) 
            console.log("Failed to call meteor..!");
        else {
            recVar.set(count);
        }
    });
 });
 Template.GetTable.helpers({
    'getTotalData':function(key1,key2){
        return recVar.get();
    },
 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM