I have a tracker function that was working fine until I edited other file and made the application a bit more complex which somehow lead to this issue. The function is not returning any data for
vrLoan
fundingData
My code:
Tracker.autorun(()=>{ // Tracker function for reactivity
const id = Session.get('data')._id;
const loans = Loans.find({fileId: id});
loans.forEach(o=>{
const vrLoan = VRLoans.find({parentId: o._id});
const fundingData = Funding.find({parentId: o._id});
const t = o.Type;
const n = o.description;
if(t && n && vrLoan.count() && fundingData.count()){
console.log("here")
fundDep.changed();
fundingNameSpace[t] = {};
if(t == "Bank Loan" || t == "Directors Loan" || t == "Lease" || t == "Loan Out/Invesment"){
fundingNameSpace[t][n] = new LoanCalc(t, vrLoan, fundingData);
}else if(t == "Share"){
fundingNameSpace[t][n] = new ShareCapCalc(vrLoan, fundingData);
}else if(t == "Other"){
fundingNameSpace[t][n] = new OtherIncomeCalc(vrLoan, fundingData);
}else if(t == "Cap"){
fundingNameSpace[t][n] = new CapitalGrantCalc(vrLoan, fundingData);
}
});
});
I guess that the new code I added must have slowed the query somehow because the length of queries is 0.
Can some one explain to me why this is happening?
Your first if
statement won't run because you check vrLoans
and fundingData
for length
, but they are mongo cursors (objects) and not actual arrays.
So instead of .length
, you want .count()
to check they aren't empty (or call .fetch()
after your find()
to get ordinary js arrays).
https://docs.mongodb.com/manual/reference/method/cursor.count/
(HOWEVER, because of this error it doesn't look like this function would ever have done anything, so presumably you must have modified it when you changed the rest of your app.)
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.