[英]TypeError: Cannot read property 'length' of null MongoDb error
Getting a mongodb error on a query. 在查询中获取mongodb错误。 Here the error:
这里的错误:
TypeError: Cannot read property 'length' of null
TypeError:无法读取null的属性“ length”
Here's the code: 这是代码:
// 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;
}
There are no documents currently in 'customers'
with the above criteria. 'customers'
当前没有符合上述条件的文件。
Change your code to: 将您的代码更改为:
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.