问题描述
我正在使用 Firebase 创建一个 NoSQL 数据库,但由于我是一名 SQL 思想家,因此我需要一些关于 Firebase 查询和 NoSQL 数据结构的建议.
I’m creating a NoSQL database using Firebase, but as I’m a SQL thinker my mind needs some advices about Firebase queries and NoSQL Data Structure.
我正在使用 Ionic 2 (AngularJS 2) 为移动应用程序做一些实验,我担心的是速度(用户时间)和我的表格的正确结构.
I am making some experiments for a Mobile App using also Ionic 2 (AngularJS 2), and my concerns are about the speed (user time) and the correct structure of my tables.
在应用程序中,我列出了用户所做的事情,并且用户可能是组的一部分,现在在 Firebase 网站的非规范化之后,我创建了这个架构
In the App I have a list of things that Users have Made and Users could be part of a Group, now following the de-normalization from the Firebase website I made this schema
Users : {
Id : {
Name: string
Picture: base64 56x56 pixels (image)
Addresses : {}
Groups : {
Worker: boolean
Student: boolean
}
}
}
Groups : {
Worker : {
Desc: string
Members : {
Userid: boolean
}
}
Student : {
Desc: string
Members : {
Userid: boolean
}
}
}
Made : {
Id : {
Name: string
Thumb: base64 56x56 pixels (image)
Desc: string
User: userid
Images: base64 dimensions could vary
}
}
我要做的是显示用户所做的事情的列表,其中包含很少的信息,例如名称和拇指图像,单击它会打开带有其他信息的描述.
What I have to do is to show a list of things that an user made, with few information like name and thumb image, by clicking on it opens the description with the other infos.
现在,如果我使用以下代码段获取列表,它会返回所有信息,但一开始我只需要姓名和拇指(或其他内容)
Now if I use the following snippet for getting the list, it returns me all the info but at the beginning I need just name and thumb (or something else)
return firebase.database().ref('/made/' + madeId)
.once('value').then(function(snapshot) {
var username = snapshot.val().username;
// ...
});
那么,firebase 中有什么方法可以做类似(?)的事情:
So, is there any way in firebase to do something like(?):
SELECT name, thumb FROM Table_Made
为了只获取每个查询我需要的字段?或者
In order to get only the fields that I need for each query? Or
最好有另一个只有名称和图像的表吗?
Is better to have another table with only the name and the image?
同时拥有拇指和图像是个好主意吗?为了加速json,因为拇指一般比图片小.
Is a good idea to have both thumb and the image? In order to speed up the json because the thumb is generally smaller than the image.
查看 Firebase 文档,似乎小于 10mb 的图像可以以 base64 格式保存到文档中,以防存储空间更大.您对此有何看法?
Looking at Firebase doc, it seems that images smaller than 10mb could be saved as base64 into the document and in case are bigger on the storage. What is your idea about that?
推荐答案
Firebase 客户端总是检索完整的节点.无法仅获取节点属性的子集.
Firebase clients always retrieve complete nodes. There is no way to get just a subset of the properties of a node.
像往常一样:如果您在数据模型上实现用例时遇到问题,请更改数据模型以适应您的用例.所以在这种情况下,这意味着您可以将名称和缩略图拆分为一个单独的节点.
As usual: if you are having problems implementing your use-case on the data model, change the data model to fit your use-case. So in this case, that means that you could split off the name and thumbnail into a separate node.
MadeListinfo : {
Id : {
Name: string
Thumb: base64 56x56 pixels (image)
}
}
这篇关于NoSQL 数据结构,用于使用 Firebase 和查询选择字段子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!