【发布时间】:2018-07-20 01:19:42
【问题描述】:
在查询中获取 mongodb 错误。这里的错误:
TypeError: 无法读取 null 的属性“长度”
代码如下:
// 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' 中目前没有符合上述条件的文档。
【问题讨论】:
-
您应该在尝试使用
result之前检查错误 -
我一定要疯了,当我在 heroku 中重新部署任何想法时,错误不再存在,除了您的建议之外,我什么也没做:dbo.collection('customers').find({therapyConfirmation: true,therapyTimeZone: 'CST',therapyDay: { $gt: 0 } }).toArray((error, result) => { if (error) { throw error; } let max = result.length;
标签: javascript node.js mongodb npm