[英]How to speed-up the mongoDB query response time in meteor?
我的集合中有至少15,000个记录,其中包含至少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;
}
});
},
});
/server/main.js
Meteor.methods({
'getCountData':function(type){
return test.find({"col_17" : " Query->:#####->x","col_8": { $regex: /^CQI?/i}}).count();
},
});
我只是在进行测试,我知道如何从数据库中获取计数。 我的问题是所有渲染和辅助程序都被调用后,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();
},
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.