簡體   English   中英

TypeError:無法讀取null MongoDb錯誤的屬性“長度”

[英]TypeError: Cannot read property 'length' of null MongoDb error

在查詢中獲取mongodb錯誤。 這里的錯誤:

TypeError:無法讀取null的屬性“ length”

這是代碼:

// Open a connection with MongoDB

MongoClient.connect(process.env.MONGO_URL, (error, db) => {
  let dbo = db.db('gamblenomore');

//Running a query to find all customers that are in timezone CST.

dbo.collection('customers').find({therapyConfirmation: true, therapyTimeZone: 'CST', therapyDay: { $gt: 0 } }).toArray((error, result) => {
    let max = result.length;
    if (error) {
      throw error;
    }

'customers'當前沒有符合上述條件的文件。

將您的代碼更改為:

dbo.collection('customers').find({
  therapyConfirmation: true,
  therapyTimeZone: 'CST', 
  therapyDay: { $gt: 0 } 
}).toArray((error, result) => {
    if (error) {
      throw error;
    }
    let max = result.length;
    // some other code
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM