我在这里谈论网络。所以基本上,我可以像这样创建一个Collection Reference:
let treeRef = firebase.firestore().collection('trees')
所以现在我想向其添加诸如where
或limit
之类的子句,因此根据the docs,我会写类似的东西:
treeRef.where('name', '==', 'yes');
treeRef.limit(5);
但是当我随后调用treeRef.get()
时,添加的子句将被忽略,它查询整个集合而不关心添加的子句。
编辑示例:
SODemo() {
const categoryRef = this.$fireStore.collection('categories');
categoryRef.limit(1);
categoryRef.get().then(querySnapshot => {
console.log(querySnapshot.size); // logs 6 in my console (collection has 6 documents)
});
}
答案 0 :(得分:1)
如文档中所述,limit()
和where()
方法“创建并返回新查询”,因此您需要执行以下操作:
SODemo() {
const categoryRef = this.$fireStore.collection('categories');
const categoryRefLimit = categoryRef.limit(1);
categoryRefLimit.get().then(querySnapshot => {
console.log(querySnapshot.size); // logs 6 in my console (collection has 6 documents)
});
}