[英]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.