1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question Firebase Firestore does not update changes

Discussion in 'Android Questions' started by musaso, Jul 27, 2019.

  1. musaso

    musaso 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

    Code:
    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 ????
     
  2. DonManfred

    DonManfred Expert Licensed 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.

    Code:
    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.
     
  3. musaso

    musaso Member Licensed User

    Could you put an example code? .Thanks
     
  4. DonManfred

    DonManfred Expert Licensed User

    This IS an Examplecode.
     
  5. DonManfred

    DonManfred Expert Licensed User

    I added a Collection Datos in my Database.
    I used this Code to add something.
    Code:
    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
    [​IMG]
     
  6. musaso

    musaso 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

    Code:
    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
    Code:
    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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice