You need to enable JavaScript to run this app. Node.js使用influxdb-client查询时报TypeError: t.complete is not a function
优惠活动
大模型
产品
解决方案
定价
更多

Node.js使用influxdb-client查询时报TypeError: t.complete is not a function

问题原因

@influxdata/influxdb-client的queryRows方法要求传入的观察者配置对象必须包含next、complete、error三个回调函数,你仅配置了next回调,当所有数据返回完毕后,库会自动调用complete回调,该方法未定义就会抛出TypeError: t.complete is not a function错误。该问题和你使用的库版本无关,属于API调用时参数缺失导致的问题。

修复方案

补全complete和error回调即可,不需要额外逻辑的场景下complete可以留空,error建议保留用于捕获异常,修改后的代码如下:

const fluxQuery =
  'from(bucket:"data") |> range(start: 0) |> filter(fn: (r) => r._measurement == "devices") |> filter(fn: (r) => r["_field"] == "wreal1") |> last()';

queryApi.queryRows(fluxQuery, {
  next(row, tableMeta) {
    const o = tableMeta.toObject(row)
    console.log(o)
  },
  // 查询无错误完成时触发,无操作可以留空
  complete() {
    console.log('数据查询完成')
  },
  // 查询过程出现错误时触发
  error(err) {
    console.error('查询出错:', err)
  }
});

内容的提问来源于stack exchange,提问作者Alvaro98

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.16 10:06:08