Firebase Database returns wrong value

868 views
Skip to first unread message

Mike Lefa

unread,
Jun 7, 2017, 9:39:22 AM6/7/17
to Firebase Google Group
Hi there

I have written a query in iOS swift to retrieve data from the firebase database. But one of the values that I get in my app is different from what is stored in the database. The android equivalent works just fine. Any idea what I am doing wrong?

Here is query:

let usersQuery = self.mRef.child("Users").child(key)

        

        usersQuery.observeSingleEvent(of: .value, with: {(snapshot) in

            

            

            

            if snapshot.exists()

            {

                let user = snapshot.value asNSDictionary

                let active = user?["active"asBool ?? false

                let online = user?["online"asBool ?? false


            }


  
             }, withCancel: {(error) -> Void in

            

            

        

    })




The database data is as follow:

{
  "37ukAaOUHzUZWqMVwhcRF7rCbDJ2" : {
    "Courses" : {
      "-KfV4NbUkwkKAI2UspE5" : {
        "active" : true,
        "dateCreated" : "18 March 2017 08:23 AM",
        "description" : "Student Description ",
        "id" : "-KfV4NbUkwkKAI2UspE5",
        "name" : "Programming 1",
        "price" : 2800,
        "special" : false
      }
    },
    "active" : true,
    "address" : "",
    "admin" : false,
    "email" : "in...@school.co.za",
    "fax" : "",
    "id" : "37ukAaOUHzUZWqMVwhcRF7rCbDJ2",
    "manager" : "Patrice",
    "online" : true,
    "phone" : "0812458202",
    "rating" : 0,
    "telephone" : "",
    "website" : ""
  },
  "EZdEz7ZqNLMAapndjgdPx5wmnf43" : {
    "Courses" : {
      "-KfGdc9qKBAWSMprUg8T" : {
        "active" : true,
        "dateCreated" : "15 March 2017 13:07 PM",
        "description" : "Used for sample descriptions",
        "id" : "-KfGdc9qKBAWSMprUg8T",
        "name" : "Test Course",
        "price" : 500,
        "special" : false
      },
      "-KjslUCQI48GH_PSA7ye" : {
        "active" : true,
        "dateCreated" : "11 May 2017 20:29 PM",
        "description" : "C# introduction course",
        "id" : "-KjslUCQI48GH_PSA7ye",
        "name" : "C# Intro",
        "price" : 250,
        "special" : false
      },
      "-KjslefUtkVeTIqh9WQn" : {
        "active" : true,
        "dateCreated" : "11 May 2017 20:30 PM",
        "description" : "Java introduction course",
        "id" : "-KjslefUtkVeTIqh9WQn",
        "name" : "Java Intro",
        "price" : 250,
        "special" : false
      }
    },
    "active" : true,
    "address" : "7 Henri St,",
    "admin" : true,
    "email" : "in...@school.co.za",
    "fax" : "",
    "id" : "EZdEz7ZqNLMAapndjgdPx5wmnf43",
    "manager" : "Patrice Tene",
    "name" : "Grill Corner  Ed",
    "online" : true,
    "phone" : "0812458203",
    "rating" : 0,
    "telephone" : "",
    "website" : "www.school.co.za"
  },
}


The result value for "active" using the above query is false for the first student only. The remaining output in correct.

Please help.

Kato Richardson

unread,
Jun 7, 2017, 10:25:43 AM6/7/17
to Firebase Google Group
Are you using disk persistence? If so, it's probably fetching the local copy before it connects and syncs to the server, since you're only grabbing it once. But it's hard to be any more specific here without some more details: you should verify `key` is correct, that the value is actually returned and not null, and probably turn on debug logging and compare that on Android and iOS:

JS:  firebase.database.enableLogging(true);
iOS:  [FIRDatabase setLoggingEnabled:YES];
Android:  FirebaseDatabase.getInstance().setLogLevel(Logger.Level.DEBUG);

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/25764393-0018-403f-b6ba-005ce83b87d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Mike Lefa

unread,
Jun 8, 2017, 2:56:01 AM6/8/17
to Firebase Google Group
Thanks Kato.

Disk persistence was actually enabled. It now works like just fine. Thanks again
Reply all
Reply to author
Forward
0 new messages