Cloud Firestore和Firebase实时数据库有什么区别? [英] What's the difference between Cloud Firestore and the Firebase Realtime Database?

查看:1052
本文介绍了Cloud Firestore和Firebase实时数据库有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google刚刚发布了Cloud Firestore,它们是用于应用程序的新文档数据库。



我一直在阅读文档,但是我没有看到Firestore和Firebase DB。

主要的一点是,Firestore使用文档和集合,与Firebase相比,它可以方便地使用查询,Firebase是一个带有JSON基础的传统noSQL数据库。

我想知道更多关于它们的区别或用法,或者Firestore是否来取代Firebase DB?

所有关于这个问题的所有内容,我建议你检查一下(或官方文档)以获得更完整的答案。



但是如果你想快速(-ish)摘要,这里是:

更好的查询和更多结构化的数据 - 虽然实时数据库只是一个巨大的JSON树,Cloud Firestore稍微有点结构化。所有的数据由文档(基本上是键值存储)和集合(文档的集合)组成。文档还会经常指向子集合,其中包含其他文档,这些文档本身可以包含其他文档等等。



这种结构化数据有两种方式可以帮助您。首先,所有的查询都很简单,这意味着您可以请求一个文档而不需要抓取下面的所有数据。这意味着您可以保持数据分层存储,而不必担心数据库保持浅层。其次,你有更强大的查询。例如,您现在可以跨多个字段进行查询,而无需创建组合(和非规格化)来自数据库其他部分的数据的组合字段。在某些情况下,Cloud Firestore将直接运行这些查询,而在其他情况下,它将自动为您创建和维护索引。



按比例设计 - Cloud Firestore将能够比实时数据库更好地扩展。需要注意的是,您的查询可以扩展到结果集的大小,而不是数据集。因此,无论您的数据集有多大,搜索都将保持快速。

手动抓取数据更轻松 - 与Realtime Database一样,可以在Cloud Firestore中设置侦听器以实时更改流。但是,如果您不想要这种行为,只需要简单的获取我的数据调用,那么Cloud Firestore也具有这种功能,而且它是作为主要用例构建的。 (它们比在实时数据库中调用好得多)

- 这基本上意味着更高的可靠性,因为您的数据一次跨多个数据中心共享。但是你仍然有很强的一致性,这意味着你可以随时进行查询,并确保你得到最新版本的数据。不同的定价模式 - 虽然实时数据库主要根据存储或网络带宽收费,但Cloud Firestore主要基于您执行的操作数量。这会更好,还是更糟?这取决于你的应用程序。为了给新闻应用程序,基于回合的多人游戏或类似自己的Stack Overflow版本提供动力,从价格的角度来看,Cloud Firestore可能看起来相当有利。对于像实时组绘图应用程序这样的应用程序,您可以通过多次更新发送给多人,这可能会比实时数据库更昂贵。



为什么您仍然可能需要使用实时数据库 - 这归结于几个原因。 1)整个对于频繁更新的应用程序来说可能会更便宜,这是我之前提到的,2)它已经存在了很长时间,并且经过数千个应用程序的测试(Cloud Firestore仍处于测试阶段),3)它有更好的延迟,当你需要一些具有可靠低延迟的实时感觉的时候,实时数据库可能会工作的更好。



对于大多数新应用程序,我们建议您查看Cloud Firestore。但是如果你有一个应用程序已经在实时数据库中,我不建议切换只是为了切换,除非你有一个令人信服的理由这样做。



<希望有所帮助!


Google just released Cloud Firestore, their new Document Database for apps.

I have been reading the documentation but I don't see a lot of differences between Firestore and Firebase DB.

The main point is that Firestore uses documents and collections which allow the easy use of querying compared to Firebase, which is a traditional noSQL database with a JSON base.

I would like to know a bit more about their differences, or usages, or whether Firestore just came to replace Firebase DB?

解决方案

So I wrote an entire blog post all about this very question, and I recommend you check it out (or the official documentation) for a more complete answer.

But if you want the quick(-ish) summary, here it is:

Better querying and more structured data -- While the Realtime Database is just a giant JSON tree, Cloud Firestore is a little more structured. All your data consists of documents (which are basically key-value stores) and collections (which are collections of documents). Documents will also frequently point to subcollections, which contain other documents, which themselves can contain other documents, and so on.

This structured data helps you out in two ways. First, all queries are shallow, meaning that you can request a document without grabbing all the data underneath. This means you can keep your data stored hierarchically in a way that makes more sense to you without having to worry about keeping your database shallow. Second, you have more powerful queries. For instance, you can now query across multiple fields without having to create those "combo" fields that combine (and denormalize) data from other parts of your database. In some cases, Cloud Firestore will just run those queries directly, and in other cases, it will automatically create and maintain indexes for you.

Designed to Scale -- Cloud Firestore will be able to scale better than the Realtime Database. It's important to note that your queries scale to the size of your result set, not your data set. So searching will remain fast no matter how large your data set might become.

Easier manual fetching of data -- Like the Realtime Database, you can set up listeners in Cloud Firestore to stream in changes in real-time. But if you don't want that kind of behavior, and just want a simple "fetch my data" call, Cloud Firestore has that as well, and it's built in as a primary use case. (They're much better than the once calls in Realtime Database-land)

Multi region support -- This basically means more reliability, as your data is shared across multiple data centers at once. But you still have strong consistency, meaning you can always make a query and be assured that you're getting the latest version of your data.

Different pricing model -- While the Realtime Database primarily charges based on storage or network bandwidth, Cloud Firestore primarily charges based on the number of operations you perform. Will this be better, or worse? It depends on your app.

For powering a news app, turn-based multiplayer game, or something like your own version of Stack Overflow, Cloud Firestore will probably look pretty favorable from a pricing standpoint. For something like a real-time group drawing app where you're sending across multiple updates a second to multiple people, it probably will be more expensive than the Realtime Database.

Why you still might want the to use the Realtime Database -- It comes down to a few reasons. 1) That whole "it'll probably be cheaper for apps that make lots of frequent updates" thing I mentioned previously, 2) It's been around for a long time and has been battle tested by thousands of apps (Cloud Firestore is still in beta), 3) It's got better latency and when you need something with reliably low latency for a real-timey feel, the Realtime Database might work better.

For most new apps, we recommend you check out Cloud Firestore. But if you have an app that's already on the Realtime Database, I don't really recommend switching just for the sake of switching, unless you have a compelling reason to do so.

Hope that helps!

这篇关于Cloud Firestore和Firebase实时数据库有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆