我如何仅在Firebase实时数据库中仅读取顶级数据,而不是所有较低级别的数据?

发布于 2025-02-10 07:39:09 字数 318 浏览 0 评论 0原文

因此,这里的简单答案是使用Firestore数据库,因为它提供了仅阅读顶级文档的功能,但是对于我的应用程序,使用实时数据库很重要,我想读取顶级数据,并且仅阅读较低级别当用户专门请求时数据。我阅读了实时数据库文档,并说 ”“在此处输入图像说明”

因此,默认情况下不允许'。我想知道是否允许其他任何方式?

So the simple answer here would be to use Firestore database, since it offers functionality to read only top level documents, but it is important for my app to use realtime database, I want to read the top level data, and only read the lower level data when user requests it specifically. I read the Realtime Database documentation and it saysenter image description here

So, it's not allowed 'by default'. I want to know if it is allowed any other way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

﹏半生如梦愿梦如真 2025-02-17 07:39:10

在Firebase实时数据库SDK中读取操作始终返回所有返回的路径下的所有数据。 SDK中没有任何方法仅返回节点下的键,而不是其下面的更多数据。

我建议更改您的数据结构以使用键具有“索引”数据结构,同时还可以保持您当前的结构。例如:

Users: {
  "userId1": {
    name: "...",
    address: "...",
    createdAt: 1932831239123,
    lastSeenAt: 1932831239127,
  },
  "userId2": {
    name: "...",
    address: "...",
    createdAt: 1632831239123,
    lastSeenAt: 1732831239127,
  }
},
UserKeys: {
  "userId1": true,
  "userId2": true
}

true userkeys节点中的值是因为您不能没有值创建路径,但没有特定的含义。

现在,您可以根据需要加载密钥或完整的配置文件。


另外,您可以使用REST API和通过参数

Read operations in the Firebase Realtime Database SDKs always return all data under all paths that are returned. There is no method in the SDKs that returns only the keys under a node, and not the further data under it.

I'd recommend changing your data structure to have an "index" data structure with just the keys, while also keeping your current structure. For example:

Users: {
  "userId1": {
    name: "...",
    address: "...",
    createdAt: 1932831239123,
    lastSeenAt: 1932831239127,
  },
  "userId2": {
    name: "...",
    address: "...",
    createdAt: 1632831239123,
    lastSeenAt: 1732831239127,
  }
},
UserKeys: {
  "userId1": true,
  "userId2": true
}

The true values in the UserKeys nodes are needed because you can't create a path without a value, but have no specific meaning.

Now you can can load just the keys, or the full profiles as needed.


Alternatively you can use the REST API and pass the shallow=true parameter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文