[英]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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.