react-native - React Native Firestore 从帖子中获取评论
问题描述
所以我有收藏评论、收藏用户和收藏帖子。如何查询 firestore 以便在我的提要屏幕上获得帖子和 ITS 评论?如果需要,我可以支付帮助。我的收藏评论有一个名为“postId”的字段来帮助解决这个问题,我的收藏帖子也有一个字段“userHandle”来帮助解决这个问题。但是怎么做这个查询呢?
解决方案
要查询您的评论集合,您可以执行以下操作。
const postId = "y7FN13SKWUDsWdKsGJiT" // example id of a post document
firestore()
.collection('comments')
// Filter results
.where('postId', '==', postId)
.get()
.then(querySnapshot => {
if (querySnapshot.exists) {
// Do something with the data
}
});
这将检索postId
字段等于您传入的值的所有评论文档。
推荐阅读
- python - 在 opencv2 中加载 ONNX 模型失败并出现 blob.type() 断言错误
- python - 如何在 2 个不同的二维数组上执行广播(Python / numpy)
- flutter - 如何在 BoxDecoration 中为 Tab 添加边距?
- node.js - 无法使用 Bitbucket Pipeline 将 Angular 8 应用程序部署到 Heroku
- vim - 通过 Homebrew 下载 vim 后,如何添加 vimtex 插件?
- react-native - 如何在功能组件中使用 React Native Switch?
- python-3.x - 在 python 中建模 JSON 数据的最佳方法
- node.js - 仅限 Chromium 代理 https
- django - Django Rest 框架:序列化器上的共享字段
- prismjs - 为什么使用 PrismJS 的 npm 项目中没有突出显示某些语言?