Javascript 如何在meteor中加快mongoDB查询响应时间?

Javascript 如何在meteor中加快mongoDB查询响应时间?,javascript,jquery,node.js,mongodb,meteor,Javascript,Jquery,Node.js,Mongodb,Meteor,我的集合中有15K的记录,至少有40个字段,我创建了一个由记录生成的表。在这个表中,我有各种文件,如图所示(来自Excel工作表)。 /client/main.js Template.GetTable.helpers({ 'getTotalData':function(key1,key2){ console.log("-------inside totalData()---------"); const projects1 = Template.ins

我的集合中有15K的记录,至少有40个字段,我创建了一个由记录生成的表。在这个表中,我有各种文件,如图所示(来自Excel工作表)。

/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;
                }
            });
        },
  });
Meteor.methods({
'getCountData':function(type){
              return test.find({"col_17" : " Query->:#####->x","col_8": { $regex: /^CQI?/i}}).count();  
    },
});
/server/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;
                }
            });
        },
  });
Meteor.methods({
'getCountData':function(type){
              return test.find({"col_17" : " Query->:#####->x","col_8": { $regex: /^CQI?/i}}).count();  
    },
});
我只是为了测试而测试,我知道如何从DB获得计数。 我的问题是在所有的渲染和助手被调用之后,UI将在没有任何计数数据的情况下加载。但当我签入调试器时,我使用“console.log()”打印了正确的计数,并且UI没有更新。
我如何解决这个问题?或者有什么有效的方法来解决这个问题吗?

用户界面的问题是,您在助手内部执行Meteor调用,并将调用结果返回给自己,而不是助手

下面是一个你正在做什么和你应该做什么的例子

不应:

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
            }
        });
    },
}))

应:

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();
    },
 });

UI的问题是,您正在帮助器内部执行Meteor调用,并将调用结果返回给自己,而不是帮助器

下面是一个你正在做什么和你应该做什么的例子

不应:

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
            }
        });
    },
}))

应:

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();
    },
 });

助手中Never use
Meteor.call
可能重复。助手中Never use
Meteor.call
可能重复。