[英]How do I get documents where a specific field exists/does not exists in Firebase Cloud Firestore?
[英]How do I get documents from Firebase / Firestore ordered by property value
我在“類別”集合中有6個文檔,如下所示:
{
color: "#eee",
index: 6,
name: "Restaurants",
}
我想檢索按索引屬性排序的這些文檔,從最小到最大排序。 我可以獲取所有文檔,但是不確定如何按索引對結果進行排序。 我也不確定是否應該從Firestore查詢它們,然后僅在客戶端上對其進行訂購。
今天,我的查詢看起來像:
var db = firebase.firestore();
db.collection("categories").get().then((querySnapshot) => {
let categories = []
querySnapshot.forEach((doc) => {
categories.push(doc.data())
});
this.setState({categories: categories});
});
謝謝!
嗨astrojams1個好問題。 這樣修改查詢:
db.collection("categories").orderBy("index")
.get()
.then((querySnapshot) => {
let categories = []
querySnapshot.forEach((doc) => {
categories.push(doc.data())
});
this.setState({categories: categories});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.