从 Firebase 实时数据库 Android 查询嵌套数据

2023-01-03移动开发问题
4

本文介绍了从 Firebase 实时数据库 Android 查询嵌套数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有下图中的结构,我想从id_Usuario"查询的节点aaa1234"中获取全部数据.我该怎么做这个查询?

I have the structure in the image below and I want to get the whole data from the node "aaa1234" querying by "id_Usuario". How can I do that query?

我试过了:

DatabaseReference root = database.getReference().child("Eventos").child("participantes");
Query query = root.orderByChild("id_Usuario").equalTo(2);

为了更清楚一点,aaa1234"是自定义键,所以在下一个节点会有所不同.

Just to be more clear, the "aaa1234" is a custom key, so it will be different in the next node.

推荐答案

我看到了两个错误.

第一个是错字,我已经在评论中标明了.您将用户 ID 存储为数字,因此不应该在 equalTo 中的值周围加上引号.所以:.equalTo(2)

The first one is a typo, which I already marked in my comment. You're storing the user ID as a number, so shouldn't have quotes around the value in equalTo. So: .equalTo(2)

第二个错误是你尝试查询的方式:

The second mistake is in the way you try to query:

DatabaseReference root = database.getReference().child("Eventos").child("participantes");

这将创建对不存在的子 Eventos/participantes 的引用.你想要做的是查询 Eventos,然后查询属性 participantes/id_Usuario.所以

This will create a reference to the non-existing child Eventos/participantes. What you want to do instead is query Eventos, but then against property participantes/id_Usuario. So

DatabaseReference root = database.getReference().child("Eventos");
Query query = root.orderByChild("participantes/id_Usuario").equalTo(2);

这篇关于从 Firebase 实时数据库 Android 查询嵌套数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何在 COCOS2d Android 中使用 CClistview?
How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)...
2024-08-12 移动开发问题
5

cocos2d-android:如何显示分数
cocos2d-android: how to display score(cocos2d-android:如何显示分数)...
2024-08-11 移动开发问题
7

Sqlite 数据库未从资产文件夹 Android 复制
Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)...
2024-04-15 移动开发问题
8

SQLite 数据库副本在由设备而不是模拟器生成时出现损坏
SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)...
2024-04-15 移动开发问题
4

安卓文件拷贝
Android file copy(安卓文件拷贝)...
2024-04-15 移动开发问题
6

Android如何在android中检测Edittext的Copy事件
Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)...
2024-04-15 移动开发问题
5