node.js - Firestore 的数据库建模。集合 - 类别
问题描述
所以我试图为firestore建模一个数据库模式。它被称为类别,我不知道如何存储项目。我试着看https://fireship.io/lessons/advanced-firestore-nosql-data-structure-examples/。看起来很合乎逻辑,有些文档保存了他们的子 ID 和父 ID,如果父级是顶级,则父级为空,但是如何将数据从后端(Node.js)发送到前端(Vue.js) .
还有其他方法吗?
解决方案
您可以使用包中的服务从 Firestore 读取数据firebase
。
假设您有一个名为的集合(在 SQL 数据库中称为表)Users
,并且您想要访问 id 为 的文档(在 SQL 数据库中称为行)1
。您可以通过以下代码段执行此操作:
import firebase from 'firebase/app'
import 'firebase/firestore'
const firestore = firebase.firestore()
const data = firestore.collection('Users').doc('1').get()
.then(snapshot => {
console.log(snapshot.data())
})
推荐阅读
- python - 从加载的 Keras 模型调用“predict_generator”时出现属性错误
- javascript - 只推送成功回调数据到数组,排除错误404
- dc.js - 如何使用带值的向量为散点图着色?
- angular - 没有出现路由
- docker - 重启 Docker 桌面导致 Gitlab-CI 备份丢失
- django - 使用 react、axios 和 DRF 的 CSRF 验证失败错误
- laravel - Laravel如何在php代码中停止计划任务
- reactjs - 使用类组件初始化 react-native 应用程序
- mongodb - 使用 concat 后跟 match 进行查找,不返回后者的结果
- c# - 试图用反斜杠和引号正则表达式字符串