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

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

问题描述

Google 刚刚发布了他们用于应用的新文档数据库 Cloud Firestore.

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

我一直在阅读文档,但我没有看到 Firestore 和 Firebase DB 之间的很多区别.

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

主要的一点是,与 Firebase 相比,Firestore 使用的文档和集合可以轻松使用查询,后者是一个基于 JSON 的传统 noSQL 数据库.

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.

我想更多地了解它们的区别或用法,或者 Firestore 是否刚刚取代 Firebase DB?

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.

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

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

更好的查询和更结构化的数据 -- 虽然实时数据库只是一个巨大的 JSON 树,但 Cloud Firestore 的结构更加结构化.您的所有数据都由文档(基本上是键值存储)和集合(即文档集合)组成.文档也会经常指向包含其他文档的子集合,子集合本身可以包含其他文档,等等.

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.

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

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.

旨在扩展 -- Cloud Firestore 将能够比实时数据库更好地扩展.请务必注意,您的查询会根据结果集的大小进行缩放,而不是根据数据集的大小.因此,无论您的数据集有多大,搜索都将保持快速.

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.

更轻松地手动获取数据 -- 与实时数据库一样,您可以在 Cloud Firestore 中设置侦听器以实时流式传输更改.但是,如果您不想要那种行为,而只想要一个简单的获取我的数据"调用,Cloud Firestore 也有,它是作为主要用例内置的.(它们比 Realtime Database-land 中的 once 调用要好得多)

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.

不同的定价模式 -- 虽然实时数据库主要根据存储或网络带宽收费,但 Cloud Firestore 主要根据您执行的操作数量收费.这会更好,还是更糟?这取决于您的应用.

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.

对于支持新闻应用、回合制多人游戏或类似您自己的 Stack Overflow 版本的东西,从定价的角度来看,Cloud Firestore 可能看起来非常有利.对于像实时群组绘图应用程序这样的应用程序,您要在一秒钟内向多人发送多个更新,它可能比实时数据库更昂贵.

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. 整个对于频繁更新的应用程序来说可能会更便宜";我之前提到的,

  1. That whole "it'll probably be cheaper for apps that make lots of frequent updates" thing I mentioned previously,

它已经存在很长时间了,并且已经过数千个应用的实战测试,

It's been around for a long time and has been battle tested by thousands of apps,

它有更好的延迟,当您需要可靠的低延迟来获得实时感觉时,实时数据库可能会更好地工作.

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.

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

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.

希望有帮助!

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

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