Android Question SOLVED Firestore WhereEqualto not Found

gregorio_adrian_gimenez

Active Member
Licensed User
Hello everyone! For some reason, this type of query is not working for me. I test with Wherewqualto2 and whereEqualToString. Returns all records in the collection.


Any help you can give me?

B4X:
    fs.Initialize("Firestore",True)


    Dim listar_vuelos As CollectionReference= fs.collection("viajes","listar_viajes")
    If Starter.auth.CurrentUser.IsInitialized Then
           
        If listar_vuelos <> Null Then
       
            listar_vuelos.orderBy("fecha_origen").whereEqualToString("usuario_Uid",Starter.auth.CurrentUser.Uid).fetch("listar_viajes_result")
            ProgressBar1.visible = True
            wait for listar_viajes_result_snapshot(success As Boolean, data As QuerySnapshot, info As String)
           If success Then
            If data.Size > 0 Then
       
                Dim documento As List = data.Documents
                CustomListView_proximos_viajes.Clear
                CustomListView_viajes_anteriores.Clear
       
                If documento.IsInitialized Then
           
                    For i = 0 To documento.Size-1
                        ProgressBar1.Visible = False
                        Dim docsnap As DocumentSnapshot = documento.Get(i)
                        docsnap.getDocumentReference("viajes")
                        Dim datos As Map = docsnap.Data
               
                        If Starter.authex.CurrentUser.Uid = datos.Get("usuario_Uid")Then
               
                            insertar_viajes(datos)
               
                        End If
       
                    Next
       
                End If
            Else
                ProgressBar1.Visible = False
                ToastMessageShow("No tiene viajes creados",False)
   
            End If
   
            End If
           
        End If
Collection viajes

upload_2019-9-16_11-26-47.png
 

Attachments

gregorio_adrian_gimenez

Active Member
Licensed User
Hi all! I tried to solve it but I didn't succeed, the field in firebase is String format. Did someone have the same thing? can my code be wrong?

neither orders the records
regards
 

DonManfred

Expert
Licensed User
listar_vuelos.orderBy("fecha_origen").whereEqualToString("usuario_Uid",Starter.auth.CurrentUser.Uid).fetch("listar_viajes_result")
after you first call this; this you get an error saying that an Index must be created for this combination of Filters?

I tried a similar thing using the data i have in my DB.

B4X:
    fs.Initialize("Firestore",True)
    Dim restaurants As CollectionReference = fs.collection("restaurants","restaurantsCollection")
    If restaurants <> Null Then
        Log("Setting query to get restaurants")
        restaurants.setEventname("restaurantsWatch","restaurantscollection")
        'restaurants.addSnapshotListener
    End If
    restaurants.orderBy("avgRating").whereEqualTo("category","Burgers").limit(25).fetch("RestaurantsWatch")

B4X:
Sub restaurantsWatch_onValue(success As Boolean, value As Object)
    Log($"restaurantsWatch_onValue(${success},${value})"$)
    If value Is DocumentSnapshot Then
        Dim docsnap As DocumentSnapshot = value
        Log("DocumentID: "&docsnap.Id)
        Log("DocumentData: "&docsnap.data)
        If docsnap.Data <> Null Then
            Dim data As Map = docsnap.Data
            Log(data)
        End If
    else if value Is DocumentReference Then
        Dim ref As DocumentReference = value
        ref.setEventname("UserWatch","Update")
        Log("DocumentReferenceId: "&ref.Id)
    End If
End Sub
Sub restaurantsWatch_Snapshot(success As Boolean, snap As QuerySnapshot, info As String)
    Log($"restaurantsWatch_Snapshot(${snap.Size},${snap})"$)
    Dim meta As SnapshotMetadata = snap.Metadata
   
    Log("hasPendingWrites="&meta.hasPendingWrites)
    Log("isFromCache="&meta.isFromCache)
    'Dim changes As List = snap.DocumentChanges
    'Log("Changes="&changes)
    Dim documents As List = snap.Documents
    'Log(documents)
    If documents.IsInitialized Then
        If documents.Size > 0 Then
            For i = 0 To documents.Size-1
                Dim docsnap As DocumentSnapshot = documents.Get(i)
                Log("DocumentNo: #"&i&": "&docsnap.Id)
                Log(docsnap.Data)
                Dim data As Map = docsnap.Data
                Log(data)
            Next
        End If
'        Log("Items in global DriversMap="&glDriverMap.Size)
'        For Each key As String In glDriverMap.Keys
'            Log("ID   = "&key)
'            Log("Data ="&glDriverMap.Get(key))
'        Next
    Else
        Log("Snapshot does not contain a list of Documents... Trying to get the data directly")
       
    End If

End Sub
restaurantsWatch_Snapshot(8,com.google.firebase.firestore.QuerySnapshot@e0198d10)
DocumentNo: #0: 4O3am09f04lnxgk6Hsw5
{city=Düren, price=2, name=Mc Donalds, avgRating=1, category=Burgers, numRatings=25}
(MyMap) {city=Düren, price=2, name=Mc Donalds, avgRating=1, category=Burgers, numRatings=25}
DocumentNo: #1: iALpqzk30KWEklysXKZt
{city=Düren, price=2, name=Mc Donalds, avgRating=1, category=Burgers, numRatings=1}
(MyMap) {city=Düren, price=2, name=Mc Donalds, avgRating=1, category=Burgers, numRatings=1}
DocumentNo: #2: e0HHfEuMLnHT2NSZd2aY
{city=Tulsa, price=2, name=Qux Eatin' Place, photo=https://storage.googleapis.com/firestorequickstarts.appspot.com/food_13.png, avgRating=1.7673517412641941, category=Burgers, numRatings=4}
(MyMap) {city=Tulsa, price=2, name=Qux Eatin' Place, photo=https://storage.googleapis.com/firestorequickstarts.appspot.com/food_13.png, avgRating=1.7673517412641941, category=Burgers, numRatings=4}
DocumentNo: #3: ITRYl38N970RocSiK6EY
{city=Boston, price=1, name=Bar Restaurant, photo=https://storage.googleapis.com/firestorequickstarts.appspot.com/food_6.png, avgRating=2.342525567779633, category=Burgers, numRatings=19}
(MyMap) {city=Boston, price=1, name=Bar Restaurant, photo=https://storage.googleapis.com/firestorequickstarts.appspot.com/food_6.png, avgRating=2.342525567779633, category=Burgers, numRatings=19}
DocumentNo: #4: rQvb3qyclVMibLTb0VFE
{city=Miami, price=3, name=Foo Eatin' Place, photo=https://storage.googleapis.com/firestorequickstarts.appspot.com/food_9.png, avgRating=2.5193607174745782, category=Burgers, numRatings=6}
(MyMap) {city=Miami, price=3, name=Foo Eatin' Place, photo=https://storage.googleapis.com/firestorequickstarts.appspot.com/food_9.png, avgRating=2.5193607174745782, category=Burgers, numRatings=6}
DocumentNo: #5: ZQ6KbLz9F8wMQnvPLysU
{city=Jacksonville, price=3, name=The Best Drive Thru, photo=https://storage.googleapis.com/firestorequickstarts.appspot.com/food_3.png, avgRating=2.5773552804094413, category=Burgers, numRatings=6}
(MyMap) {city=Jacksonville, price=3, name=The Best Drive Thru, photo=https://storage.googleapis.com/firestorequickstarts.appspot.com/food_3.png, avgRating=2.5773552804094413, category=Burgers, numRatings=6}
DocumentNo: #6: sIfzIVpcYBhXVq7VJ3hr
{city=Portland, price=3, name=Foo Eatery, photo=https://storage.googleapis.com/firestorequickstarts.appspot.com/food_10.png, avgRating=2.5854711611344063, category=Burgers, numRatings=19}
(MyMap) {city=Portland, price=3, name=Foo Eatery, photo=https://storage.googleapis.com/firestorequickstarts.appspot.com/food_10.png, avgRating=2.5854711611344063, category=Burgers, numRatings=19}
DocumentNo: #7: u4RjSXI71IEr84slosUV
{city=Charlotte, price=3, name=Sam's Drive Thru, photo=https://storage.googleapis.com/firestorequickstarts.appspot.com/food_8.png, avgRating=3.086751562646601, category=Burgers, numRatings=10}
(MyMap) {city=Charlotte, price=3, name=Sam's Drive Thru, photo=https://storage.googleapis.com/firestorequickstarts.appspot.com/food_8.png, avgRating=3.086751562646601, category=Burgers, numRatings=10}
** Activity (main) Pause, UserClosed = false **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Service (firebasemessaging) Destroy **
** Service (starter) Destroy (ignored)**
As you can see it is only filtering Items with the category set to "Burgers".



It may possible that i did changed the Lib in the meantime. I´ll upload a new copy in case this is the problem.

Edit to add: Check v0.67 on Dropbox.
 
Top