NoSQL 数据结构,用于使用 Firebase 和查询选择字段子集

NoSQL Data structure to select subset of fields with Firebase and query(NoSQL 数据结构,用于使用 Firebase 和查询选择字段子集)
本文介绍了NoSQL 数据结构,用于使用 Firebase 和查询选择字段子集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在使用 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 和查询选择字段子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I can get a text of all the cells of the table using testcafe(如何使用 testcafe 获取表格中所有单元格的文本)
node_modules is not recognized as an internal or external command(node_modules 未被识别为内部或外部命令)
How can I create conditional test cases using Protractor?(如何使用 Protractor 创建条件测试用例?)
PhantomJS and clicking a form button(PhantomJS 并单击表单按钮)
Clicking #39;OK#39; on alert or confirm dialog through jquery/javascript?(在警报上单击“确定或通过 jquery/javascript 确认对话框?)
QunitJS-Tests don#39;t start: PhantomJS timed out, possibly due to a missing QUnit start() call(QunitJS-Tests 不启动:PhantomJS 超时,可能是由于缺少 QUnit start() 调用)