簡體   English   中英

使用數組查詢 firestore 中的文檔列表

[英]Query a list of documents in firestore using an array

是否可以使用 ID 數組查詢 firestore 中的文檔列表?

const UserIDs = ['zHYYvrVPLA9LOV6edwOrQhQLt6k1', 'JhUvvrNbfD9LOV6edwOrQhQLt8Gf'
'] //each ID in the array is an existent document id in the collection Users

const selectedUsers = await firestore().collection('Users').doc(UserIDs).get();

盡管存在具有給定 ID 的文檔,但 selectedUsers.data() 未定義。 我知道我可以執行循環,我只是想知道我嘗試的方式是否可行。

您可以使用in運算符FieldPath.documentId() function 來構建一個查詢,該查詢最多可以按 ID 獲取 10 個文檔。

就像是:

firestore().collection('Users')
  .where(FieldPath.documentId(), 'in', UserIDs)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM