I'm building an Android application in which the user can track its weight and progress by inserting their weight (optional) AND/OR upload a picture (optional).
{
"users" : {
"5aHvYy5wTIVAAgdOEso0wr2woHS2" : {
"firstName" : "Justin",
"logs" : [ {
"date" : "16/05/2018",
"progressPicture" : "http://www.google.com/example.jpg",
"weight" : 82.1
}, {
"date" : "17/05/2018",
"progressPicture" : "http://www.google.com/example.jpg"
}, {
"date" : "18/05/2018",
"weight" : 80.3
} ]
}
}
I have managed to get the latest log by ordering by key and limiting the result to 1, using the following code.
firebaseDatabase.getReference(USER_REFERENCE).child(firebaseAuth.currentUser?.uid).child(LOG_REFERENCE).orderByKey().limitToLast(1).
As can be seen from my JSON, a log doesn't necessarily have to have a weight value.
MY QUESTION: How can I adjust my query so that I'll retrieve my latest log (so 1 log only based on key) where there is a value for weight?