Firebase-实时数据库:orderByChild和EqualTo不返回所有匹配的子级

时间:2020-07-11 16:12:58

标签: android firebase-realtime-database

当我添加数据时,我正在使用持久性为“ 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) {

                }
            });

Here is a screenshot of my application where I have added transactions but they are not added to the recyclerview

0 个答案:

没有答案