【发布时间】:2020-10-15 15:53:53
【问题描述】:
我在这里有这个 Firestore 代码,我想通过 createdAt desc 来订购它。但是,当我运行它时,它还将所有相同的用户分组在一起。您可以在https://gamecrawl.com 看到相同的用户放在一起的效果。我在这里做错了什么。
只有在我添加了一个查询以从 users 集合中获取昵称后才会发生这种情况。
var self = this;
let db = firebase.firestore();
db.collection("posts")
.orderBy("createdAt", "desc")
.get()
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
self.channelId = doc.data().ytChannelId;
self.userId = doc.data().uid;
let getUser = db.collection("users").where("uid", "==", self.userId);
getUser.get().then(function(snapshot) {
snapshot.forEach(function(snapDoc) {
self.nickname = snapDoc.data().username;
console.log("nickname 73493");
console.log(self.nickname);
self.queryData.push({
index: self.currentIndex,
pid: doc.data().pid,
title: doc.data().ytTitle,
description: doc.data().ytDescription,
imageurl: doc.data().ytImageUrl,
ytid: doc.data().ytid,
channelTitle: doc.data().ytChannelTitle,
channelId: doc.data().ytChannelId,
recommendation: doc.data().recommendation,
userphoto: doc.data().photourl,
votes: doc.data().noOfVotes,
nickname: self.nickname
});
self.currentIndex = self.currentIndex + 1;
});
});
// console.log(doc.id, " => ", doc.data());
});
})
.catch(function(error) {
console.log("Error getting documents: ", error);
});
}
【问题讨论】:
标签: javascript firebase google-cloud-firestore