![](/img/trans.png)
[英]How to delete an object in an array based on a query in Cloud Firestore using JavaScript
[英]How to query the array from the firestore using javascript?
所以,我有一個如下圖所示的 Firestore。 如何查詢我僅突出顯示為 javascript 格式的 arrays?
Firestore 入門的方法是使用 [array-contains](https://firebase.google.com/docs/firestore/query-data/queries#:~:text=const%20q%20%3D%20query (citiesRef%2C%20where(%22regions,array_contains_filter.js) 看起來像他們的例子:
const q = query(citiesRef, where("regions", "array-contains", "west_coast"));
但我看到的是它只顯示'west_coast'這個詞,我想要的是它會在名為'amount'和'title'的字段中顯示任何信息,如上圖所示
恐怕你不能。 您需要檢索整個products
數組並在本地進行過濾。
這會導致您的數據在 Firestore 中的結構。 如果那是您需要的查詢,那么您的數據可能具有不同的結構。
例如:
products
可以是ordered
的子集合ordered
文檔可能會將您需要查詢的數據存儲在一個單獨的簡化數組中(如titles: [...], amounts: [...]
,但這對排序或數字范圍沒有幫助) .看看: https://firebase.google.com/docs/firestore/manage-data/structure-data示例和用例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.