I want to retrieve data from Google Firebase RTDB.
My Current Structure in RTDB is like this:
“organization”
- 2024-05 (yearMonth)
— organizationId
—— audits
———– audit_id
————-score
————-location_id
So the score and location_id is on the same level, under certain audit_id
Here’s my current query code:
DataSnapshot auditData = await auditRef
.child(yearMonth)
.child(currentActiveOrganizationID)
.child("audits")
.orderByChild('location_id')
.equalTo(locationID)
.get();
if (auditData.value != null) {
Map<dynamic, dynamic> auditMap = auditData.value as Map<dynamic, dynamic>;
List auditMapKey = auditMap.keys.toList();
int score = auditMap[auditMapKey[0]]['score'];
return score;
} else {
return null;
}
I want to get the audit score, but from this query I have to fetch all of the other data under the audit_id such as “audited_by”, “audited_at”
How to make it more simple ?