You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Firebase模块化SDK查询Geohash时遇TypeError: q.get不是函数

解决Firebase模块化SDK中TypeError: q.get is not a function错误

问题出在Firestore模块化SDK的API使用逻辑上——模块化SDK里的查询对象没有.get()方法,你需要用独立的getDocs()函数来执行查询,这是它和命名空间SDK的核心差异。

修正后的代码

首先确认已导入getDocs函数:

import { getDocs, query, collection, orderBy, startAt, endAt } from "firebase/firestore";

然后修改查询执行的关键部分:

// Find cities within Dkm of [lat, lng]
const center = [Number(lat), Number(lng)];
const radiusInM = dist * 1000;
const bounds = geohashQueryBounds(center, radiusInM);
const promises = [];

for (const b of bounds) {
    const q = query(
        collection(db, USERS_COL),
        orderBy('geohash'),
        startAt(b[0]),
        endAt(b[1])
    );
    // 替换原有的 q.get() 为 getDocs(q)
    promises.push(getDocs(q));
}

原因说明

旧的命名空间SDK中,查询对象自带.get()方法触发查询;但模块化SDK采用函数式设计,把数据获取逻辑拆成了独立的getDocs()函数,必须将查询对象作为参数传入该函数,才能返回包含结果的Promise。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.10 02:55:14