Android Question Firebase Firestore does not update changes

musaso

Active Member
Licensed User
I have problems with Firestore, when I add a document the changes are not updated in the console, and in the log it says hasPendingWrites = true isFromCache = true

B4X:
 Sub Activity_Create(FirstTime As Boolean)
      fs.Initialize("Firestore",True)
        
        'Public datos As CollectionReference
        datos = fs.collection("datos", "datos")
        datos.setEventname("leerdatos","leerdatos")
        datos.addSnapshotListener
        
        'Public todos As DocumentReference
        todos = fs.document("datos/todos")
        todos.setEventname("leertodos","leertodos")
        todos.addSnapshotListener
End Sub

Sub leerdatos_Snapshot(success As Boolean, snap As QuerySnapshot, info As String)
    Log($"leerdatos_Snapshot(${snap.Size},${snap})"$)
    Dim meta As SnapshotMetadata = snap.Metadata
    Log("hasPendingWrites= - " & meta.hasPendingWrites &" isFromCache = - " & meta.isFromCache)
End Sub

Sub BotonEscribir_Click
   If fs.isInitialized Then
       Dim fecha As Long =  DateTime.Now
       Dim m As Map = CreateMap("hora": DateTime.GetHour(fecha),"minuto":DateTime.GetMinute(fecha),"segundo":DateTime.GetSecond(fecha))
       todos.update(m,"")
   End If
End Sub

Log
leerdatos_Snapshot(4,com.google.firebase.firestore.QuerySnapshot@4d027fd1)
hasPendingWrites= - true isFromCache = - true
DocumentNo: #0: ZIQzCB1RpquKJTl0FNpb
(MyMap) {hora=12, segundo=53, minuto=48}
DocumentNo: #1: todos
(MyMap) {hora=13, segundo=0, minuto=15}
DocumentNo: #2: uGe0APYBwyzgre1hcNFd
(MyMap) {hora=12, segundo=56, minuto=49}
DocumentNo: #3: vEFaoha6y742ReSCvje2
(MyMap) {hora=12, segundo=34, minuto=49}
leertodos_onevent(DocumentSnapshot{key=datos/todos, metadata=SnapshotMetadata{hasPendingWrites=true, isFromCache=true}, doc=Document{key=datos/todos, data=ArraySortedMap{(hora=>13), (minuto=>15), (segundo=>0)};, version=SnapshotVersion(seconds=0, nanos=0), documentState=LOCAL_MUTATIONS}})
(MyMap) {hora=13, segundo=0, minuto=15}

These documents do not appear on the console ????
 

DonManfred

Expert
Licensed User
Longtime User
I don´t know if that is the correct approach.

In my eperiences i need to have a collectionreference and can Create new Documents in there using a Map. Or a customclass.

B4X:
    Dim fecha As Long =  DateTime.Now
    Dim m As Map = CreateMap("hora": DateTime.GetHour(fecha),"minuto":DateTime.GetMinute(fecha),"segundo":DateTime.GetSecond(fecha))
    datos.add(m)

You are creating a local Document. This document is not transfered.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I added a Collection Datos in my Database.
I used this Code to add something.
B4X:
    fs.Initialize("Firestore",True)
    Dim datos As CollectionReference = fs.collection("Datos","DatosCollection")
    If datos <> Null Then
        Log("Setting query to get Datos")
        datos.setEventname("DatosWatch","Datoscollection")
        datos.addSnapshotListener
        Dim fecha As Long =  DateTime.Now
        Dim m As Map = CreateMap("hora": DateTime.GetHour(fecha),"minuto":DateTime.GetMinute(fecha),"segundo":DateTime.GetSecond(fecha))
        datos.add(m)
    End If
It results in this Data in my Console
firestoredatos085.png
 
Upvote 0

musaso

Active Member
Licensed User
I must have some problem that I have not been able to solve for several days.
I have copied the code as is and cannot update the data.

1º- I must create the Sub DataWatch_Snapshot sub, otherwise I get an error.
2º-The Log in this sub keeps putting me hasPendingWrites = true isFromCache = true

B4X:
Sub DatosWatch_Snapshot(success As Boolean, snap As QuerySnapshot, info As String)
    Log($"DatosWatch_Snapshot(${snap.Size},${snap})"$)
    Dim meta As SnapshotMetadata = snap.Metadata
    Log("hasPendingWrites = " & meta.hasPendingWrites &" isFromCache = " & meta.isFromCache)
End Sub

Log
B4X:
DatosWatch_Snapshot(3,com.google.firebase.firestore.QuerySnapshot@4b7eb4b)
hasPendingWrites =  true isFromCache =  true

You can see that there are 3 collections (3 times I try) but in the console it is not updated.
 
Upvote 0
Top