简体   繁体   English

流星收集未获取数据

[英]Meteor Collection not fetching data

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 该函数不返回任何数据

  1. vrLoan
  2. 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. 我猜我添加的新代码一定会以某种方式减慢查询速度,因为查询的长度为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. 您的第一个if语句不会运行,因为您检查了vrLoansfundingDatalength ,但是它们是mongo游标(对象),而不是实际的数组。

So instead of .length , you want .count() to check they aren't empty (or call .fetch() after your find() to get ordinary js arrays). 因此,您希望.count()而不是.length来检查它们是否为空(或在.fetch()之后调用.fetch() find()以获取普通的js数组)。

https://docs.mongodb.com/manual/reference/method/cursor.count/ 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.) (但是,由于这个错误,它似乎无法执行任何操作,因此,大概在更改应用程序的其余部分时必须对其进行了修改。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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