Android Question SOLVED Firestore WhereEqualto not Found

gregorio_adrian_gimenez

Active Member
Licensed User
Longtime 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

 

Attachments

  • upload_2019-9-16_11-25-54.png
    214.8 KB · Views: 253

gregorio_adrian_gimenez

Active Member
Licensed User
Longtime 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
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime 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


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.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…