简体   繁体   English

Firestore 在 google-cloud firestore 上查询“IN”

[英]Firestore where 'IN' query on google-cloud firestore

(Using typescript for better readability. Vanilla js is always welcome) (使用打字稿以获得更好的可读性。Vanilla js 总是受欢迎的)

Nodejs App, using these imports: Nodejs App,使用这些导入:

import { FieldPath, DocumentReference } from '@google-cloud/firestore';

and this function和这个功能

async getByIds(ids: DocumentReference[]) {
    const collection = this.db.client.collection('authors');
    const query = await collection.where(FieldPath.documentId(), 'in', ids).get();

    return query.docs.map(d => ({ id: d.id, ...d.data() }));
}

returns this very specific error:返回这个非常具体的错误:

The corresponding value for FieldPath.documentId() must be a string or a DocumentReference.

The debugger confirms that ids is in fact a DocumentReference array.调试器确认 ids 实际上是一个 DocumentReference 数组。

Maybe the @google-cloud/firestore package isn't aligned to the firebase one?也许@google-cloud/firestore软件包与@google-cloud/firestore软件包不一致?

EDIT: as noted by Doug in it's comment, I forgot to put the code for this.db.client .编辑:正如 Doug 在评论中指出的那样,我忘了为this.db.client放置代码。 Here you are:这个给你:

export class DatabaseProvider {
    private _db: Firestore;
    get client(): Firestore {
        return this._db;
    }

    constructor() {
        this._db = new Firestore({
            projectId: ...,
            keyFilename: ...
        });
    }
}

And used as并用作

const db = new DatabaseProvider();

It seems like what you're trying to do is a batch get, which is available via a different method: getAll() .看起来您要做的是批量获取,可以通过不同的方法获取: getAll() I think you want this:我想你想要这个:

async getByIds(ids: DocumentReference[]) {
  return this.db.client.getAll(...ids);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于导出 Firestore 备份数据的云功能。 使用 firebase-admin 还是 @google-cloud/firestore? - Cloud function to export Firestore backup data. Using firebase-admin or @google-cloud/firestore? 如何通过 getUserByPhoneNumber 使用 google-cloud firestore 身份验证获取用户记录? - How to get the user Record using the google-cloud firestore auth by getUserByPhoneNumber? 使用 node.js 标准环境在 AppEngine 上找不到模块 @google-cloud/firestore - Cannot find module @google-cloud/firestore on AppEngine using node.js standard environment 构建失败:npm ERR! @google-cloud/firestore 无法从 firebase-admin 访问 - Build failed: npm ERR! @google-cloud/firestore not accessible from firebase-admin 在Google云端防火墙中执行JOIN查询 - Perform JOIN query in google cloud firestore Cloud Firestore 数据查询 - Cloud Firestore Data Query Google Cloud Firestore仅查询时间戳早于x的文档 - Google Cloud Firestore only query documents where timestamp is older than x Cloud Firestore 和 Google Cloud 凭据 - Cloud Firestore and Google Cloud Credentials 在Cloud Functions中,从何处导入Firestore`Query`类型? - In Cloud Functions, where to import the Firestore `Query` type from? 为什么FireStore查询不起作用? - Why is FireStore where query not working?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM