我想检索用户订阅/关注的所有博客(如Instagram)。我正在使用Firebase Cloud Functions和Firestore。
exports.currentUserSubscriberPost = (req, res) => {
const subscriberDoc = db
.collection("subscriber")
.where("userHandle", "==", req.user.handle);
let subscribing = [];
const BlogsDoc = db.collection("blogs");
subscriberDoc
.get()
.then(async doc => {
doc.forEach(data => {
subscribing.push({ subscribingUserId: data.data().userId });
});
if (subscribing.length > 0) {
let ref = subscribing.map((user) => db.collection('blogs').where('userId','==',user.subscribingUserId));
let blogsData = await db.getAll(...ref);
return blogsData;
} else {
return res.json({ msg: "you are not subscribing to anyOne" });
}
})
.then(data => {
let blogs = [];
data.forEach(data => {
blogs.push( data.data() );
});
return res.json(blogs);
}).catch(err => console.error(err))
};