After retrieving group key in HashMap how to perform join query which shows only those grp
details which have member as that particular user. And if this structure is wrong please help me with this.
Structure:
Calling the getKey() method on this reference will return the auto-generated key which may then be used to store a corresponding value. Using Firebase to generate unique keys in this way is also of particular use when an app has multiple users creating child nodes at the same path in the tree.
A simultaneous connection is equivalent to one mobile device, browser tab, or server app connected to the database. This isn't the same as the total number of users of your app, because your users don't all connect at once.
A DataSnapshot instance contains data from a Firebase Database location. Any time you read Database data, you receive the data as a DataSnapshot. DataSnapshots are passed to the methods in listeners that you attach with addValueEventListener , addChildEventListener , or addListenerForSingleValueEvent .
Use
DatabaseReference
inside anotherDatabaseReference
:
// any way you managed to go the node that has the 'grp_key'
DatabaseReference MembersRef = FirebaseDatabase.getInstance()
.getReference()
.child("Members")
.child("1CkPG20Tt2dzrVkYkdfCLo")
.orderByKey().equalTo("-KYnhiAucnasdkadNC")
.addValueEventListener(
new ValueEventListener()
{
@Override
public void onDataChange(DataSnapshot dataSnapshot)
{
for (DataSnapshot child : dataSnapshot.getChildren())
{
Map<String, Object> valuesMap = (HashMap<String, Object>) dataSnapshot.getValue();
// Get push id value.
String key = valuesMap.get("grp_key");
// HERE WHAT CORRESPONDS TO JOIN
DatabaseReference chatGroupRef = FirebaseDatabase.getInstance().getReference()
.child("Chat_groups")
.orderByKey().equalTo(key)
.addValueEventListener(
new ValueEventListener()
{
@Override
public void onDataChange(DataSnapshot dataSnapshot)
{
// repeat!!
}
@Override
public void onCancelled(DatabaseError databaseError)
{
}
}
)
}
}
@Override
public void onCancelled(DatabaseError databaseError)
{
}
}
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With