简体   繁体   English

Firebase检查是否存在返回false,它应该返回true

[英]Firebase checking if exists returns false where it should return true

I'm trying to check if a user with a particular email exists or not. 我正在尝试检查是否存在具有特定电子邮件的用户。 The user with this email is in the database so the check should have returned true instead of false. 使用此电子邮件的用户位于数据库中,因此检查应返回true而不是false。

Here's the schema: 这是架构:

在此输入图像描述

Here's the code: 这是代码:

final DatabaseReference userRef = FirebaseDatabase.getInstance().getReference().child("users");
userRef.orderByChild("email").equalTo("rafael.adel20@gmail.com").limitToFirst(1).addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        System.out.println(dataSnapshot); //returns { key = users, value = null }
        if(dataSnapshot.getChildrenCount() > 0) {
            //user already exists (Never executed)
        } else {
            //user doesn't exists (Always executed)
        }
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {

    }
});

If setPersistenceEnabled(true) is called, use of addListenerForSingleValueEvent can cause local cached version of data to be returned rather than latest version from server (whereas calling addValueEventListener will ensure you get latest version). 如果setPersistenceEnabled(true) ,则使用addListenerForSingleValueEvent可以导致返回本地缓存版本的数据,而不是从服务器返回最新版本(而调用addValueEventListener将确保获得最新版本)。 Another approach, if using addListenerForSingleValueEvent is to call query.keepSynced(true); 另一种方法,如果使用addListenerForSingleValueEvent则调用query.keepSynced(true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TreeSet在应返回true时返回false? - TreeSet returns false when it should return true? 测试视图是否存在,但我的方法返回 false - 它应该返回 true - Testing to see if view exists, but my method returns false - it should return true m.find() 在应该返回 true 时返回 false - m.find() returns false when it should return true 测试返回true,而返回false,反之亦然 - The test returns true, while it should return false and vice versa 即使应该返回false,循环也返回true - Loop returns true even when should return false 比较应该返回true但返回false - Comparison should return true but return false 哈希集返回false何时应返回true - hashset return false when should return true 为什么'File.exists'返回true,即使NIO'Files'类中的'Files.exists'返回false - Why does 'File.exists' return true, even though 'Files.exists' in the NIO 'Files' class returns false 为什么这种方法存在逻辑错误。 isPalindrome(11) 应该返回 true,但它返回 false - Why there is a logic error with this method. isPalindrome(11) should return true, but it returns false 任何人都可以看到我错在哪里,我的代码应该返回 true 但它返回 false 它不应该返回 - Can anyone see where i am wrong , My code should return true but its returning false which it should not be returning
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM