【问题标题】:How to access different realtime databses in my firebase project?如何在我的 firebase 项目中访问不同的实时数据库?
【发布时间】:2020-07-21 04:56:37
【问题描述】:

我正在使用firebase realtime DB。在其中我选择了右侧的 3 个点并创建了第二个数据库,它的名称是:“project-SomeNumberString”

在我的应用程序中,我现在如何访问该数据库而不是原始数据库(只是缺少数字字符串)?

【问题讨论】:

  • @twothreezarsix 你能扩展一下吗?
  • @twothreezarsix 是的,您的假设是正确的。下半场不过看不懂

标签: ios swift firebase firebase-realtime-database


【解决方案1】:

documentation on sharding 中描述了您要执行的操作。您将特别希望使用“Connect your app to multiple database instances”部分中的示例代码:

使用数据库引用访问存储在辅助数据库中的数据 实例。您可以获得特定数据库实例的参考 通过 URL 或应用程序。如果您不指定 URL,您将获得参考 为应用程序的默认数据库实例。

// Get the default database instance for an app

var ref: DatabaseReference!

ref = Database.database().reference()


// Get a secondary database instance by URL
var ref: DatabaseReference!

ref = Database.database("https://testapp-1234.firebaseio.com").reference()

您将需要使用此辅助实例进行查询。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-13
    • 2021-06-14
    • 2021-04-22
    • 2019-04-13
    • 2019-03-23
    相关资源
    最近更新 更多