javascript - TypeError:无法读取 null MongoDb 错误的属性“长度”
问题描述
在查询中获取 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'
符合上述标准的文件。
解决方案
将您的代码更改为:
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
});
推荐阅读
- reactjs - 路由重定向到 url 但不渲染视图
- html - 我怎样才能移动这些小图像?
- google-sheets - Google 表格查询:仅在不同的列中返回所有行数据
- c# - 在参数化的查询中重写没有前缀 N 和没有单引号的查询是否有区别
- powershell - A Get-ChildItem 内的 Get-ChildItem
- ruby-on-rails - 未从浏览器缓存加载 application.css 文件
- vb.net - OracleDataAdapter,没有命令超时和填充方法挂起
- pandas - 转置后如何调用列?
- python - 无法关闭使用 pdfplumber open() 打开的 pdf 文件
- flutter - 为什么 Dart 中的 const Widget 不相同?