当我添加数据时,我正在使用持久性为“ ON”的Firebase实时数据库...它将添加到服务器,但是当我使用orderByChild()和equalTo()查询数据时,并非所有匹配的子级都将返回。
firebaseDatabase.setPersistenceEnabled(true);
在应用程序类中启用keepSync()
db.child("Users").orderByChild("_id").equalTo(_id_user).keepSynced(true);
db.child("Khatas").orderByChild("_id_user").equalTo(_id_user).keepSynced(true);
db.child("Customers").orderByChild("_id_user_khata").equalTo(_id_user_khata).keepSynced(true);
db.child("Transactions").orderByChild("_id_user_khata").equalTo(_id_user_khata).keepSynced(true);
db.child("Business Card").orderByChild("_id_user_khata").equalTo(_id_user_khata).keepSynced(true);
查询数据库
db.child(Constants.root_TRANSACTIONS)
.orderByChild(Constants.transaction__ID_USER_KHATA_CUSTOMER)
.equalTo(Repository.firebaseUser.getUid() + id_SEPERATOR + currentlyOpened_Khata_ID + id_SEPERATOR + customerID)
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
if(snapshot.exists()){
List<Transaction> transactions = new ArrayList<>();
for(DataSnapshot data : snapshot.getChildren()){
Transaction transaction = data.getValue(Transaction.class);
transactions.add(transaction);
}
transactionList = transactions;
rv_transactions.setAdapter(new Transactions_Adapter(
requireActivity(),
transactions));
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});