我有一个很大的注册列表,我希望在前5个较少且最常用的列表中显示:
我不知道Firebase Cloud Firestore对此类操作的查询是什么样的。要从主题中的集合中检索数据,我使用:
getUserRegistrations() {
var user = firebase.auth().currentUser;
var userUID = user.uid;
db
.collection("registrations")
.orderBy("date", "desc")
.where("uid", "==", userUID)
.get()
.then(querySnapshot => {
const userRegistrations = [];
querySnapshot.forEach(doc => {
const data = {
registration_id: doc.id,
experience_id: doc.data().experience_id,
uid: doc.data().uid,
title: doc.data().title,
date: doc.data().date
};
userRegistrations.push(data);
});
this.userRegistrations = userRegistrations;
});
},
答案 0 :(得分:0)
您可以使用limit()
功能仅列出5个文档:
db
.collection("registrations")
.where("uid", "==", userUID)
.orderBy("date", "desc")
.limit(5)
.get()
.then(querySnapshot => {
const userRegistrations = [];
querySnapshot.forEach(doc => {
const data = {
registration_id: doc.id,
experience_id: doc.data().experience_id,
uid: doc.data().uid,
title: doc.data().title,
date: doc.data().date
};
userRegistrations.push(data);
});
this.userRegistrations = userRegistrations;
});