gpt4 book ai didi

javascript - 在 Firebase 函数中按 documentId 查询

转载 作者:行者123 更新时间:2023-12-01 15:56:01 24 4
gpt4 key购买 nike

当我使用 documentId 作为字段路径从 Firebase Firestore 查询数据时,在网页 (javascript) 和 Firebase 函数 (Node.js) 上运行脚本时会出现不同的行为。

这个javascript给了我完美的结果:

firebase.firestore().collection('test')
.where(firebase.firestore.FieldPath.documentId(), '<=', 'ccc')
.get()
.then(snapshots => { /* results are here */ });

相比之下,Firebase 函数 (Node.js) 中的相同代码:
admin.firestore().collection('test')
.where(admin.firestore.FieldPath.documentId(), '<=', 'ccc')
.get()
.then(snapshots => { /* ... */ });

给我一个错误:

Error: { Error: a filter on __name__ must be a document resource name at ClientReadableStream._emitStatusIfDone (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:255:19) at ClientReadableStream._receiveStatus (/user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:233:8) at /user_code/node_modules/firebase-admin/node_modules/grpc/src/client.js:705:12 code: 3, metadata: Metadata { _internal_repr: {} } }



我使用自己的文档 ID,我想通过这些 ID 进行查询。我知道我可以通过查询某个文档的内部字段来解决这个问题,但我的问题是:这种不同行为的原因是什么?非常感谢。

我的 Firebase 版本是 3.17.4

编辑:此错误已解决,并且未出现在 Firebase 版本 3.18.2 中。

最佳答案

这确实是 Node SDK 的一个功能遗漏,我们将在下一个版本中解决。

您现在可以通过直接传递 DocumentReference 来解决这个问题:

const coll = admin.firestore().collection('test')
coll
.where(admin.firestore.FieldPath.documentId(), '<=', coll.doc('ccc'))
.get()
.then(snapshots => { /* ... */ });

关于javascript - 在 Firebase 函数中按 documentId 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48788805/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com