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

使用Nuxt Firebase的where查询报错:FieldPath.assess未定义

Nuxt Firebase Firestore查询报错解决方案

错误根源

你代码里写的FieldPath.assess()是拼写错误——Firestore的FieldPath类根本没有assess这个方法,你应该是想调用FieldPath.documentId()来针对文档ID做筛选查询。

修正后的代码

this.$fire.firestore.collection('lights')
    .where(this.$fireModule.firestore.FieldPath.documentId(), '==', 'ZxBc9dMxVdodbHtnAf5g')
    .get()
    .then(snapshot => {
        // 这里写处理查询结果的逻辑
        snapshot.forEach(doc => {
            console.log(doc.id, '对应数据:', doc.data());
        });
    })
    .catch(error => {
        console.error('查询失败:', error);
    });

额外验证点

  • 检查nuxt.config.js里不仅要启用functions,还要确保Firestore服务已开启:
    // nuxt.config.js 相关配置示例
    modules: [
      ['@nuxtjs/firebase', {
        config: {
          // 填入你的Firebase项目配置信息
        },
        services: {
          firestore: true, // 必须开启此项才能使用Firestore
          functions: true
        }
      }]
    ]
    
  • 如果是在asyncData或nuxtServerInit这类服务器端/异步钩子中调用,需要通过上下文参数(比如context.$fire、context.$fireModule)来获取Firebase实例,而不是直接用this。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 23:54:29