首页 > 解决方案 > Firestore 的数据库建模。集合 - 类别

问题描述

所以我试图为firestore建模一个数据库模式。它被称为类别,我不知道如何存储项目。我试着看https://fireship.io/lessons/advanced-firestore-nosql-data-structure-examples/。看起来很合乎逻辑,有些文档保存了他们的子 ID 和父 ID,如果父级是顶级,则父级为空,但是如何将数据从后端(Node.js)发送到前端(Vue.js) .

还有其他方法吗?

标签: node.jsfirebasevue.jsgoogle-cloud-firestoredata-modeling

解决方案


您可以使用包中的服务从 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())  
               })

推荐阅读