[英]Firestore query where(documentId(), 'in', array) is giving me an error
I'm trying to run a query for documents in a collection that match an array of ids (custom document ids), and I'm getting this error:我正在尝试查询与 id 数组(自定义文档 id)匹配的集合中的文档,但出现此错误:
Error: The corresponding value for FieldPath.documentId() must be a string or a DocumentReference.
错误:FieldPath.documentId() 的对应值必须是字符串或 DocumentReference。
Here is my code:这是我的代码:
const admin = require('firebase-admin');
const db = admin.firestore();
let ids = ['12_5', '12_6'];
db.collection('myCollection').where(admin.firestore.FieldPath.documentId(), 'in', ids).get()
The documents exist in Firestore, and I created them with custom document ids to be able to easily retrieve the exact documents I need.这些文档存在于 Firestore 中,我使用自定义文档 ID 创建它们,以便能够轻松检索我需要的确切文档。 My Documents in Firestore
我在 Firestore 中的文档
Any ideas on how I can resolve this error?关于如何解决此错误的任何想法?
Remove the package-lock.json lock file then install the latest @google-cloud/firestore删除 package-lock.json 锁文件然后安装最新的@google-cloud/firestore
As of Dec 2022, this now works without issue.截至 2022 年 12 月,这现在可以正常工作。
firebase-admin@^11.2.0
defines where
this way: firebase-admin@^11.2.0
以这种方式where
:
where(
fieldPath: string | FieldPath,
opStr: WhereFilterOp,
value: any
): Query<T>;
So where
will no longer require just DocumentReference
or string
, but instead accept a FieldPath
.因此
where
将不再只需要DocumentReference
或string
,而是接受FieldPath
。 The OP's code will now work without errors using a recent version of firebase-admin
or @google-cloud/firestore
. OP 的代码现在可以使用最新版本的
firebase-admin
或@google-cloud/firestore
正常运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.